Java Code Examples for java.time.ZonedDateTime#getOffset()

The following examples show how to use java.time.ZonedDateTime#getOffset() . 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: TimeMetadataProvider.java    From recheck with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Map<String, String> retrieve() {
	final Map<String, String> map = new HashMap<>();

	final ZonedDateTime now = ZonedDateTime.now();
	final LocalTime time = now.toLocalTime();
	final LocalDate date = now.toLocalDate();
	final ZoneId zone = now.getZone();
	final ZoneOffset offset = now.getOffset();

	map.put( TIME, time.format( TIME_FORMATTER ) );
	map.put( DATE, date.format( DATE_FORMATTER ) );
	map.put( ZONE, zone.getId() );
	map.put( OFFSET, offset.getId() );

	return map;
}
 
Example 2
Source File: ZonedDateTimeHandle.java    From joyrpc with Apache License 2.0 5 votes vote down vote up
@Override
public void wrap(final ZonedDateTime zonedDateTime) {
    this.dateTime = zonedDateTime.toLocalDateTime();
    this.offset = zonedDateTime.getOffset();
    if (zonedDateTime.getZone() != null) {
        this.zoneId = zonedDateTime.getZone().getId();
    }
}
 
Example 3
Source File: TestDateUtil.java    From java-trader with Apache License 2.0 5 votes vote down vote up
@Test
public void testZoneOffset(){
    LocalDateTime dt = LocalDateTime.now();

    ZoneId zoneId = Exchange.SSE.getZoneId();
    ZonedDateTime zdt = dt.atZone(zoneId);
    ZoneOffset ofs = zdt.getOffset();
}
 
Example 4
Source File: SunMoonCalculator.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
public void calcEphemeris(final ZoneId ZONE_ID) {
    try {
        setTwilight(TWILIGHT.HORIZON_34arcmin);
        calcSunAndMoon();
        LocalDateTime now        = LocalDateTime.now();
        ZonedDateTime zdt        = now.atZone(ZONE_ID);
        ZoneOffset    zoneOffset = zdt.getOffset();

        sunriseZDT = getZonedDateTime(sunrise, zoneOffset);
        sunsetZDT = getZonedDateTime(sunset, zoneOffset);

        // Calculate golden hour
        setTwilight(TWILIGHT.GOLDEN_HOUR);
        calcSunAndMoon();
        sunriseGoldenHourZDT = getZonedDateTime(sunrise, zoneOffset);
        sunsetGoldenHourZDT = getZonedDateTime(sunset, zoneOffset);

        // Calculate civil twilight
        setTwilight(TWILIGHT.TWILIGHT_CIVIL);
        calcSunAndMoon();
        sunriseCivilZDT = getZonedDateTime(sunrise, zoneOffset);
        sunsetCivilZDT = getZonedDateTime(sunset, zoneOffset);

        // Calculate blue hour
        setTwilight(TWILIGHT.BLUE_HOUR);
        calcSunAndMoon();
        sunriseBlueHourZDT = getZonedDateTime(sunrise, zoneOffset);
        sunsetBlueHourZDT = getZonedDateTime(sunset, zoneOffset);
    } catch (Exception e) {
        sunriseZDT           = ZonedDateTime.now();
        sunsetZDT            = ZonedDateTime.now();
        sunriseGoldenHourZDT = ZonedDateTime.now();
        sunsetGoldenHourZDT  = ZonedDateTime.now();
        sunriseCivilZDT      = ZonedDateTime.now();
        sunsetCivilZDT       = ZonedDateTime.now();
        sunriseBlueHourZDT   = ZonedDateTime.now();
        sunsetBlueHourZDT    = ZonedDateTime.now();
    }
}
 
Example 5
Source File: NtpOSGiTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDateTimeChannelDefaultTimeZoneUpdate() {
    ZonedDateTime zoned = ZonedDateTime.now();

    ZoneOffset expectedTimeZone = zoned.getOffset();
    Configuration configuration = new Configuration();
    // Initialize with configuration with no time zone property set.
    initialize(configuration, NtpBindingConstants.CHANNEL_DATE_TIME, ACCEPTED_ITEM_TYPE_DATE_TIME, null, null);

    String testItemState = getItemState(ACCEPTED_ITEM_TYPE_DATE_TIME).toString();
    assertFormat(testItemState, DateTimeType.DATE_PATTERN_WITH_TZ_AND_MS);
    ZoneOffset timeZoneFromItemRegistry = new DateTimeType(testItemState).getZonedDateTime().getOffset();

    assertEquals(expectedTimeZone, timeZoneFromItemRegistry);
}
 
Example 6
Source File: ZonedDateTimeHandle.java    From alibaba-rsocket-broker with Apache License 2.0 4 votes vote down vote up
public ZonedDateTimeHandle(ZonedDateTime o) {
    this.dateTime = o.toLocalDateTime();
    this.offset = o.getOffset();
    this.zoneId = o.getZone().getId();
}