List of usage examples for java.time ZonedDateTime getZone
@Override
public ZoneId getZone()
From source file:Main.java
public static void main(String[] args) { ZonedDateTime dateTime = ZonedDateTime.now(); System.out.println(dateTime.getZone()); }
From source file:Main.java
public static void main(String[] args) { GregorianCalendar gc = new GregorianCalendar(2014, 1, 11, 15, 45, 50); LocalDate ld = gc.toZonedDateTime().toLocalDate(); System.out.println("Local Date: " + ld); LocalTime lt = gc.toZonedDateTime().toLocalTime(); System.out.println("Local Time: " + lt); LocalDateTime ldt = gc.toZonedDateTime().toLocalDateTime(); System.out.println("Local DateTime: " + ldt); OffsetDateTime od = gc.toZonedDateTime().toOffsetDateTime(); System.out.println("Offset Date: " + od); OffsetTime ot = gc.toZonedDateTime().toOffsetDateTime().toOffsetTime(); System.out.println("Offset Time: " + ot); ZonedDateTime zdt = gc.toZonedDateTime(); System.out.println("Zoned DateTime: " + zdt); ZoneId zoneId = zdt.getZone(); TimeZone timeZone = TimeZone.getTimeZone(zoneId); System.out.println("Zone ID: " + zoneId); System.out.println("Time Zone ID: " + timeZone.getID()); GregorianCalendar gc2 = GregorianCalendar.from(zdt); System.out.println("Gregorian Calendar: " + gc2.getTime()); }
From source file:Main.java
/** * Checks if the type of the given date. Possible return values are standard * time, the date when to switch to daylight saving time (in Europe the last * Sunday in March), daylight saving time or the date when to switch back to * standard time (in Europe the last Sunday in October). * // w w w .j av a 2s .c o m * @return DayType * @param cal * Date to check, cannot be null */ public static DayType getDSTType(LocalDate cal) { DayType status = DayType.DAYLIGHT_SAVING_TIME; LocalDateTime testDate = cal.atStartOfDay(); ZonedDateTime zdt = ZonedDateTime.of(testDate, ZoneId.systemDefault()); // Find type of day if (zdt.getZone().getRules().isDaylightSavings(testDate.toInstant(zdt.getOffset()))) status = DayType.DAYLIGHT_SAVING_TIME; else status = DayType.STANDARD_TIME; // Check the day after testDate = testDate.plusDays(1); zdt = ZonedDateTime.of(testDate, ZoneId.systemDefault()); // Find type of day after if (zdt.getZone().getRules().isDaylightSavings(testDate.toInstant(zdt.getOffset()))) { if (status != DayType.DAYLIGHT_SAVING_TIME) status = DayType.TO_DAYLIGHT_SAVING_TIME; } else { if (status == DayType.DAYLIGHT_SAVING_TIME) status = DayType.TO_STANDARD_TIME; } return status; }
From source file:cz.muni.fi.pv168.project.hotelmanager.TestReservationManagerImpl.java
private static Clock prepareClockMock(ZonedDateTime now) { return Clock.fixed(now.toInstant(), now.getZone()); }
From source file:com.teradata.benchto.service.BenchmarkService.java
private ZonedDateTime fromInstantOrCurrentDateTime(Optional<Instant> instant) { ZonedDateTime currentDateTime = currentDateTime(); return instant.map(i -> i.atZone(currentDateTime.getZone())).orElse(currentDateTime); }
From source file:it.tidalwave.northernwind.frontend.media.impl.DefaultMetadataCacheTest.java
/******************************************************************************************************************* * ******************************************************************************************************************/ private void setTime(final @Nonnull ZonedDateTime dateTime) { mockClock = Clock.fixed(dateTime.toInstant(), dateTime.getZone()); log.info("==== Time set to {}", ZonedDateTime.now(mockClock)); }
From source file:nu.yona.server.analysis.service.InactivityManagementService.java
private WeekActivity createWeekInactivity(UUID userAnonymizedId, UUID goalId, ZonedDateTime weekStartTime) { return createInactivity(userAnonymizedId, goalId, () -> weekActivityRepository.findOne(userAnonymizedId, weekStartTime.toLocalDate(), goalId), (ua, g) -> WeekActivity.createInstance(ua, g, weekStartTime.getZone(), weekStartTime.toLocalDate()), wa -> wa.getGoal().addWeekActivity(wa)); }
From source file:io.stallion.jobs.Schedule.java
/** * Gets the next datetime matching the schedule, passing in the current * date from which to look. Used for testing. * * @param startingFrom/*from w w w. ja va 2s . c o m*/ * @return */ public ZonedDateTime nextAt(ZonedDateTime startingFrom) { if (!startingFrom.getZone().equals(getZoneId())) { startingFrom = startingFrom.withZoneSameInstant(getZoneId()); } ZonedDateTime dt = new NextDateTimeFinder(startingFrom).find(); return dt.withZoneSameInstant(ZoneId.of("UTC")); }
From source file:nu.yona.server.analysis.service.ActivityUpdateService.java
private DayActivity createNewDayActivity(UserAnonymized userAnonymizedEntity, ActivityPayload payload, Goal matchingGoal) {//from w ww . ja v a2s . co m DayActivity dayActivity = DayActivity.createInstance(userAnonymizedEntity, matchingGoal, payload.startTime.getZone(), TimeUtil.getStartOfDay(payload.userAnonymized.getTimeZone(), payload.startTime).toLocalDate()); dayActivityRepository.save(dayActivity); ZonedDateTime startOfWeek = TimeUtil.getStartOfWeek(payload.userAnonymized.getTimeZone(), payload.startTime); WeekActivity weekActivity = weekActivityRepository.findOne(payload.userAnonymized.getId(), matchingGoal.getId(), startOfWeek.toLocalDate()); if (weekActivity == null) { weekActivity = WeekActivity.createInstance(userAnonymizedEntity, matchingGoal, startOfWeek.getZone(), startOfWeek.toLocalDate()); matchingGoal.addWeekActivity(weekActivity); } weekActivity.addDayActivity(dayActivity); return dayActivity; }
From source file:org.primeframework.mvc.parameter.convert.converters.ZonedDateTimeConverterTest.java
@Test public void fromStrings() { GlobalConverter converter = new ZonedDateTimeConverter(new MockConfiguration()); ZonedDateTime value = (ZonedDateTime) converter.convertFromStrings(ZonedDateTime.class, null, "testExpr", ArrayUtils.toArray((String) null)); assertNull(value);//from w ww .j a v a2 s. co m value = (ZonedDateTime) converter.convertFromStrings(Locale.class, MapBuilder.asMap("dateTimeFormat", "MM-dd-yyyy hh:mm:ss a Z"), "testExpr", ArrayUtils.toArray("07-08-2008 10:13:34 AM -0800")); assertEquals(value.getMonthValue(), 7); assertEquals(value.getDayOfMonth(), 8); assertEquals(value.getYear(), 2008); assertEquals(value.getHour(), 10); assertEquals(value.getMinute(), 13); assertEquals(value.getSecond(), 34); assertEquals(value.getZone(), ZoneOffset.ofHours(-8)); try { converter.convertFromStrings(Locale.class, MapBuilder.asMap("dateTimeFormat", "MM-dd-yyyy"), "testExpr", ArrayUtils.toArray("07/08/2008")); fail("Should have failed"); } catch (ConversionException e) { // Expected } }