Java Code Examples for java.time.ZonedDateTime#get()
The following examples show how to use
java.time.ZonedDateTime#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RoundLcdClockSkin.java From Medusa with Apache License 2.0 | 6 votes |
private void drawHours(final ZonedDateTime TIME) { int hourCounter = 1; int hour = TIME.getHour(); double strokeWidth = size * 0.06; hoursCtx.setLineCap(StrokeLineCap.BUTT); hoursCtx.clearRect(0, 0, size, size); for (int i = 450 ; i >= 90 ; i--) { hoursCtx.save(); if (i % 30 == 0) { //draw hours hoursCtx.setStroke(hourColor); hoursCtx.setLineWidth(strokeWidth); if (hour == 0 || hour == 12) { hoursCtx.strokeArc(strokeWidth * 0.5, strokeWidth * 0.5, size - strokeWidth, size - strokeWidth, i + 1 - 30, 28, ArcType.OPEN); } else if (hourCounter <= (TIME.get(ChronoField.AMPM_OF_DAY) == 1 ? hour - 12 : hour)) { hoursCtx.strokeArc(strokeWidth * 0.5, strokeWidth * 0.5, size - strokeWidth, size - strokeWidth, i + 1 - 30, 28, ArcType.OPEN); hourCounter++; } } hoursCtx.restore(); } }
Example 2
Source File: DateUtil.java From java-trader with Apache License 2.0 | 5 votes |
public static Duration between(LocalDateTime datetime1, LocalDateTime datetime2) { if (datetime1.isAfter(datetime2)) { return between(datetime2, datetime1); } ZonedDateTime zonedTime1 = datetime1.atZone(defaultZoneId); ZonedDateTime zonedTime2 = datetime2.atZone(defaultZoneId); long seconds = zonedTime2.toEpochSecond() - zonedTime1.toEpochSecond(); long nanoAdjustment = zonedTime2.get(ChronoField.NANO_OF_SECOND) - zonedTime1.get(ChronoField.NANO_OF_SECOND); return Duration.ofSeconds(seconds, nanoAdjustment); }
Example 3
Source File: DesignClockSkin.java From Medusa with Apache License 2.0 | 5 votes |
@Override public void updateTime(final ZonedDateTime TIME) { double rotationAngle = 0.5 * (60 * TIME.getHour() + TIME.getMinute() + TIME.getSecond() * 0.0166666667 + TIME.get(ChronoField.MILLI_OF_SECOND) * 0.0000166667); double rotationX = size * 0.5 + rotationRadius * Math.sin(Math.toRadians(rotationAngle + 180)); double rotationY = size * 0.5 - rotationRadius * Math.cos(Math.toRadians(rotationAngle + 180)); tickCanvas.relocate(rotationX - tickCanvas.getHeight() * 0.5, rotationY - tickCanvas.getHeight() * 0.5); needle.setRotate(rotationAngle); double canvasCenterX = tickCanvas.getWidth() * 0.5; double canvasCenterY = tickCanvas.getHeight() * 0.5; double radius = tickCanvas.getHeight() * 0.372; double rotX = canvasCenterX + radius * Math.sin(Math.toRadians(rotationAngle)); double rotY = canvasCenterY - radius * Math.cos(Math.toRadians(rotationAngle)); clip.setCenterX(rotX); clip.setCenterY(rotY); }
Example 4
Source File: Helper.java From Medusa with Apache License 2.0 | 5 votes |
public static final void drawTimeSections(final Clock CLOCK, final GraphicsContext CTX, final List<TimeSection> SECTIONS, final double SIZE, final double XY_INSIDE, final double XY_OUTSIDE, final double WH_INSIDE, final double WH_OUTSIDE, final double LINE_WIDTH) { if (SECTIONS.isEmpty()) return; TickLabelLocation tickLabelLocation = CLOCK.getTickLabelLocation(); ZonedDateTime time = CLOCK.getTime(); boolean isAM = time.get(ChronoField.AMPM_OF_DAY) == 0; double xy = TickLabelLocation.INSIDE == tickLabelLocation ? XY_INSIDE * SIZE : XY_OUTSIDE * SIZE; double wh = TickLabelLocation.INSIDE == tickLabelLocation ? WH_INSIDE * SIZE : WH_OUTSIDE * SIZE; double offset = 90; int listSize = SECTIONS.size(); double angleStep = 360.0 / 60.0; boolean highlightSections = CLOCK.isHighlightSections(); for (int i = 0 ; i < listSize ; i++) { TimeSection section = SECTIONS.get(i); LocalTime start = section.getStart(); LocalTime stop = section.getStop(); boolean isStartAM = start.get(ChronoField.AMPM_OF_DAY) == 0; boolean isStopAM = stop.get(ChronoField.AMPM_OF_DAY) == 0; boolean draw = isAM ? (isStartAM || isStopAM) :(!isStartAM || !isStopAM); if (draw) { double sectionStartAngle = (start.getHour() % 12 * 5.0 + start.getMinute() / 12.0 + start.getSecond() / 300.0) * angleStep + 180; double sectionAngleExtend = ((stop.getHour() - start.getHour()) % 12 * 5.0 + (stop.getMinute() - start.getMinute()) / 12.0 + (stop.getSecond() - start.getSecond()) / 300.0) * angleStep; //TODO: Add an indicator to the section like -1 or similar // check if start was already yesterday if (start.getHour() > stop.getHour()) { sectionAngleExtend = (360.0 - Math.abs(sectionAngleExtend)); } CTX.save(); if (highlightSections) { CTX.setStroke(section.contains(time.toLocalTime()) ? section.getHighlightColor() : section.getColor()); } else { CTX.setStroke(section.getColor()); } CTX.setLineWidth(SIZE * LINE_WIDTH); CTX.setLineCap(StrokeLineCap.BUTT); CTX.strokeArc(xy, xy, wh, wh, -(offset + sectionStartAngle), -sectionAngleExtend, ArcType.OPEN); CTX.restore(); } } }
Example 5
Source File: Helper.java From Medusa with Apache License 2.0 | 5 votes |
public static final void drawTimeAreas(final Clock CLOCK, final GraphicsContext CTX, final List<TimeSection> AREAS, final double SIZE, final double XY_INSIDE, final double XY_OUTSIDE, final double WH_INSIDE, final double WH_OUTSIDE) { if (AREAS.isEmpty()) return; TickLabelLocation tickLabelLocation = CLOCK.getTickLabelLocation(); ZonedDateTime time = CLOCK.getTime(); boolean isAM = time.get(ChronoField.AMPM_OF_DAY) == 0; double xy = TickLabelLocation.OUTSIDE == tickLabelLocation ? XY_OUTSIDE * SIZE : XY_INSIDE * SIZE; double wh = TickLabelLocation.OUTSIDE == tickLabelLocation ? WH_OUTSIDE * SIZE : WH_INSIDE * SIZE; double offset = 90; double angleStep = 360.0 / 60.0; int listSize = AREAS.size(); boolean highlightAreas = CLOCK.isHighlightAreas(); for (int i = 0; i < listSize ; i++) { TimeSection area = AREAS.get(i); LocalTime start = area.getStart(); LocalTime stop = area.getStop(); boolean isStartAM = start.get(ChronoField.AMPM_OF_DAY) == 0; boolean isStopAM = stop.get(ChronoField.AMPM_OF_DAY) == 0; boolean draw = isAM ? (isStartAM || isStopAM) :(!isStartAM || !isStopAM); if (draw) { double areaStartAngle = (start.getHour() % 12 * 5.0 + start.getMinute() / 12.0 + start.getSecond() / 300.0) * angleStep + 180;; double areaAngleExtend = ((stop.getHour() - start.getHour()) % 12 * 5.0 + (stop.getMinute() - start.getMinute()) / 12.0 + (stop.getSecond() - start.getSecond()) / 300.0) * angleStep; //TODO: Add an indicator to the area like -1 or similar // check if start was already yesterday if (start.getHour() > stop.getHour()) { areaAngleExtend = (360.0 - Math.abs(areaAngleExtend)); } CTX.save(); if (highlightAreas) { CTX.setFill(area.contains(time.toLocalTime()) ? area.getHighlightColor() : area.getColor()); } else { CTX.setFill(area.getColor()); } CTX.fillArc(xy, xy, wh, wh, -(offset + areaStartAngle), -areaAngleExtend, ArcType.ROUND); CTX.restore(); } } }
Example 6
Source File: TimerControlTileSkin.java From OEE-Designer with MIT License | 4 votes |
private void drawTimeSections() { if (sectionMap.isEmpty()) return; ZonedDateTime time = tile.getTime(); DayOfWeek day = time.getDayOfWeek(); boolean isAM = time.get(ChronoField.AMPM_OF_DAY) == 0; double offset = 90; double angleStep = 360.0 / 60.0; boolean highlightSections = tile.isHighlightSections(); for (TimeSection section : sectionMap.keySet()) { LocalTime start = section.getStart(); LocalTime stop = section.getStop(); boolean isStartAM = start.get(ChronoField.AMPM_OF_DAY) == 0; boolean isStopAM = stop.get(ChronoField.AMPM_OF_DAY) == 0; boolean draw = isAM ? (isStartAM || isStopAM) : (!isStartAM || !isStopAM); if (!section.getDays().contains(day)) { draw = false; } if (!section.isActive()) { draw = false; } if (draw) { double sectionStartAngle = (start.getHour() % 12 * 5.0 + start.getMinute() / 12.0 + start.getSecond() / 300.0) * angleStep + 180; double sectionAngleExtend = ((stop.getHour() - start.getHour()) % 12 * 5.0 + (stop.getMinute() - start.getMinute()) / 12.0 + (stop.getSecond() - start.getSecond()) / 300.0) * angleStep; if (start.getHour() > stop.getHour()) { sectionAngleExtend = (360.0 - Math.abs(sectionAngleExtend)); } Arc arc = sectionMap.get(section); arc.setCenterX(clockSize * 0.5); arc.setCenterY(clockSize * 0.5); arc.setRadiusX(clockSize * 0.45); arc.setRadiusY(clockSize * 0.45); arc.setStartAngle(-(offset + sectionStartAngle)); arc.setLength(-sectionAngleExtend); arc.setType(ArcType.OPEN); arc.setStrokeWidth(clockSize * 0.04); arc.setStrokeLineCap(StrokeLineCap.BUTT); arc.setFill(null); if (highlightSections) { arc.setStroke(section.contains(time.toLocalTime()) ? section.getHighlightColor() : section.getColor()); } else { arc.setStroke(section.getColor()); } } } }
Example 7
Source File: BasicForwardHandler.java From calendar-component with Apache License 2.0 | 4 votes |
@Override public void forward(CalendarComponentEvents.ForwardEvent event) { int firstDay = event.getComponent().getFirstVisibleDayOfWeek(); int lastDay = event.getComponent().getLastVisibleDayOfWeek(); ZonedDateTime start = event.getComponent().getStartDate(); ZonedDateTime end = event.getComponent().getEndDate(); long durationInDays; // for week view durationInDays = 7, for day view durationInDays = 1 if (event.getComponent().isDayMode()) { // day view durationInDays = 1; } else if (event.getComponent().isWeeklyMode()) { durationInDays = 7; } else { durationInDays = Duration.between(start, end).toDays() +1; } start = start.plus(durationInDays, ChronoUnit.DAYS); end = end.plus(durationInDays, ChronoUnit.DAYS); if (event.getComponent().isDayMode()) { // day view int dayOfWeek = start.get(ChronoField.DAY_OF_WEEK); ZonedDateTime newDate = start; while (!(firstDay <= dayOfWeek && dayOfWeek <= lastDay)) { newDate = newDate.plus(1, ChronoUnit.DAYS); dayOfWeek = newDate.get(ChronoField.DAY_OF_WEEK); } setDates(event, newDate, newDate); return; } if (durationInDays < 28) { setDates(event, start, end); } else { // go 7 days forth and get the first day from month setDates(event, start.with(firstDayOfMonth()), end.plus(7, ChronoUnit.DAYS).with(firstDayOfMonth())); } }
Example 8
Source File: BasicBackwardHandler.java From calendar-component with Apache License 2.0 | 4 votes |
@Override public void backward(CalendarComponentEvents.BackwardEvent event) { int firstDay = event.getComponent().getFirstVisibleDayOfWeek(); int lastDay = event.getComponent().getLastVisibleDayOfWeek(); ZonedDateTime start = event.getComponent().getStartDate(); ZonedDateTime end = event.getComponent().getEndDate(); long durationInDays; // for week view durationInDays = 7, for day view durationInDays = 1 if (event.getComponent().isDayMode()) { // day view durationInDays = 1; } else if (event.getComponent().isWeeklyMode()) { durationInDays = 7; } else { durationInDays = Duration.between(start, end).toDays() +1; } start = start.minus(durationInDays, ChronoUnit.DAYS); end = end.minus(durationInDays, ChronoUnit.DAYS); if (event.getComponent().isDayMode()) { // day view int dayOfWeek = start.get(ChronoField.DAY_OF_WEEK); ZonedDateTime newDate = start; while (!(firstDay <= dayOfWeek && dayOfWeek <= lastDay)) { newDate = newDate.minus(1, ChronoUnit.DAYS); dayOfWeek = newDate.get(ChronoField.DAY_OF_WEEK); } setDates(event, newDate, newDate); return; } if (durationInDays < 28) { setDates(event, start, end); } else { // go 7 days before and get the last day from month setDates(event, start.minus(7, ChronoUnit.DAYS).with(lastDayOfMonth()), end.with(lastDayOfMonth())); } }
Example 9
Source File: TimerControlTileSkin.java From tilesfx with Apache License 2.0 | 4 votes |
private void drawTimeSections() { if (sectionMap.isEmpty()) return; ZonedDateTime time = tile.getTime(); DayOfWeek day = time.getDayOfWeek(); boolean isAM = time.get(ChronoField.AMPM_OF_DAY) == 0; double offset = 90; double angleStep = 360.0 / 60.0; boolean highlightSections = tile.isHighlightSections(); for (TimeSection section : sectionMap.keySet()) { LocalTime start = section.getStart(); LocalTime stop = section.getStop(); boolean isStartAM = start.get(ChronoField.AMPM_OF_DAY) == 0; boolean isStopAM = stop.get(ChronoField.AMPM_OF_DAY) == 0; boolean draw = isAM ? (isStartAM || isStopAM) : (!isStartAM || !isStopAM); if (!section.getDays().contains(day)) { draw = false; } if (!section.isActive()) { draw = false; } if (draw) { double sectionStartAngle = (start.getHour() % 12 * 5.0 + start.getMinute() / 12.0 + start.getSecond() / 300.0) * angleStep + 180; double sectionAngleExtend = ((stop.getHour() - start.getHour()) % 12 * 5.0 + (stop.getMinute() - start.getMinute()) / 12.0 + (stop.getSecond() - start.getSecond()) / 300.0) * angleStep; if (start.getHour() > stop.getHour()) { sectionAngleExtend = (360.0 - Math.abs(sectionAngleExtend)); } Arc arc = sectionMap.get(section); arc.setCenterX(clockSize * 0.5); arc.setCenterY(clockSize * 0.5); arc.setRadiusX(clockSize * 0.45); arc.setRadiusY(clockSize * 0.45); arc.setStartAngle(-(offset + sectionStartAngle)); arc.setLength(-sectionAngleExtend); arc.setType(ArcType.OPEN); arc.setStrokeWidth(clockSize * 0.04); arc.setStrokeLineCap(StrokeLineCap.BUTT); arc.setFill(null); if (highlightSections) { arc.setStroke(section.contains(time.toLocalTime()) ? section.getHighlightColor() : section.getColor()); } else { arc.setStroke(section.getColor()); } } } }
Example 10
Source File: BattleLogs.java From logbook-kai with MIT License | 4 votes |
@Override public boolean accept(ZonedDateTime target, ZonedDateTime now) { TemporalField field = ChronoField.DAY_OF_YEAR; return now.get(field) == target.get(field); }
Example 11
Source File: BattleLogs.java From logbook-kai with MIT License | 4 votes |
@Override public boolean accept(ZonedDateTime target, ZonedDateTime now) { TemporalField field = WeekFields.ISO.weekOfWeekBasedYear(); return now.get(field) == target.get(field); }
Example 12
Source File: BattleLogs.java From logbook-kai with MIT License | 4 votes |
@Override public boolean accept(ZonedDateTime target, ZonedDateTime now) { TemporalField field = ChronoField.MONTH_OF_YEAR; return now.get(field) == target.get(field); }
Example 13
Source File: BattleLogs.java From logbook-kai with MIT License | 4 votes |
@Override public boolean accept(ZonedDateTime target, ZonedDateTime now) { TemporalField field = WeekFields.ISO.weekOfWeekBasedYear(); return now.minusWeeks(1).get(field) == target.get(field); }
Example 14
Source File: BattleLogs.java From logbook-kai with MIT License | 4 votes |
@Override public boolean accept(ZonedDateTime target, ZonedDateTime now) { TemporalField field = ChronoField.MONTH_OF_YEAR; return now.minusMonths(1).get(field) == target.get(field); }
Example 15
Source File: DateFunctions.java From jphp with Apache License 2.0 | 4 votes |
public static Memory idate(Environment env, TraceInfo traceInfo, String format, long time) { if (format.length() != 1) { env.warning(traceInfo, "idate(): idate format is one char"); return Memory.FALSE; } char c = format.charAt(0); ZonedDateTime dateTime = zonedDateTime(env, traceInfo, time); long ret; switch (c) { case 'B': // https://stackoverflow.com/questions/22693794/how-do-i-get-the-current-time-in-swatch-internet-time-in-java ZonedDateTime dt = dateTime.withZoneSameInstant(ZoneId.of("UTC+01:00")); ret = (int) ((dt.get(ChronoField.SECOND_OF_MINUTE) + (dt.get(ChronoField.MINUTE_OF_HOUR) * 60) + (dt.get(ChronoField.HOUR_OF_DAY) * 3600)) / 86.4); break; case 'd': ret = dateTime.getDayOfMonth(); break; case 'h': ret = dateTime.getHour() % 12; break; case 'H': ret = dateTime.getHour(); break; case 'i': ret = dateTime.getMinute(); break; case 'I': boolean dst = dateTime.getZone().getRules().isDaylightSavings(dateTime.toInstant()); ret = dst ? 1 : 0; break; case 'L': ret = Year.isLeap(dateTime.getYear()) ? 1 : 0; break; case 'm': ret = dateTime.getMonthValue(); break; case 's': ret = dateTime.getSecond(); break; case 't': ret = dateTime.getMonth().length(Year.isLeap(dateTime.getYear())); break; case 'U': ret = time; break; case 'w': // 0 - Sunday ret = dateTime.getDayOfWeek().getValue(); break; case 'W': ret = dateTime.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR); break; case 'y': ret = dateTime.getYear() % 100; break; case 'Y': ret = dateTime.getYear(); break; case 'z': ret = dateTime.getDayOfYear() - 1; break; case 'Z': ret = dateTime.toOffsetDateTime().getOffset().getTotalSeconds(); break; default: env.warning(traceInfo, "idate(): Unrecognized date format token"); return Memory.FALSE; } return LongMemory.valueOf(ret); }