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

The following examples show how to use java.time.OffsetDateTime#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: PNGMetadata.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
void initImageCreationTime(OffsetDateTime offsetDateTime) {
    // Check for incoming arguments
    if (offsetDateTime != null) {
        // set values that make up Standard/Document/ImageCreationTime
        creation_time_present = true;
        creation_time_year    = offsetDateTime.getYear();
        creation_time_month   = offsetDateTime.getMonthValue();
        creation_time_day     = offsetDateTime.getDayOfMonth();
        creation_time_hour    = offsetDateTime.getHour();
        creation_time_minute  = offsetDateTime.getMinute();
        creation_time_second  = offsetDateTime.getSecond();
        creation_time_offset  = offsetDateTime.getOffset();
    }
}
 
Example 2
Source File: DateTimeSupplierTest.java    From cerberus with Apache License 2.0 5 votes vote down vote up
@Test
public void test_now_returns_utc_time() {
  final OffsetDateTime dateTime = subject.get();
  final ZoneOffset offset = dateTime.getOffset();

  assertThat(offset.getTotalSeconds()).isEqualTo(0);
}
 
Example 3
Source File: Main.java    From Java-Coding-Problems with MIT License 4 votes vote down vote up
public static void main(String[] args) {

        System.out.println("Before JDK 8:");
        TimeZone timeZoneAP = TimeZone.getTimeZone("Australia/Perth");
        int offsetFromTimeZone = timeZoneAP.getRawOffset();
        String userFriendlyOffsetTimeZone = formatOffset(offsetFromTimeZone);
        System.out.println("Offset from TimeZone (Australia/Perth): " + userFriendlyOffsetTimeZone);

        Calendar calendar = Calendar.getInstance();
        // Summer time in Bucharest: 
        // Sunday, 31 March 2019, 1h forward -  Sunday, 27 October 2019, 1 hour backward
        // month 6 is a summer month in Bucharest, so you will get +03:00
        // month 11 is a winter month in Bucharest, so you will get +02:00
        calendar.set(2019, 11, 15);
        TimeZone timeZoneEB = TimeZone.getTimeZone("Europe/Bucharest");
        timeZoneEB.useDaylightTime();
        int offsetFromDate = timeZoneEB.getOffset(calendar.getTime().getTime());
        String userFriendlyOffsetDate = formatOffset(offsetFromDate);
        System.out.println("Offset from Calendar (Europe/Bucharest): " + userFriendlyOffsetDate);

        // JDK 8
        System.out.println("\n\nStarting with JDK 8:");
        // returns Z, which is +00:00
        ZoneOffset zoneOffsetUTC = ZoneOffset.UTC;
        System.out.println("ZoneOffset UTC: " + zoneOffsetUTC);
        // getting the system default time zone
        ZoneId defaultZoneId = ZoneOffset.systemDefault();
        System.out.println("Default zone id: " + defaultZoneId);

        // by default it deals with the Daylight Saving Times
        LocalDateTime ldt = LocalDateTime.of(2019, 3, 15, 0, 0);
        ZoneId zoneId = ZoneId.of("Europe/Bucharest");
        ZoneOffset zoneOffset = zoneId.getRules().getOffset(ldt);
        System.out.println("\nZoneOffset from LocalDateTime (Europe/Bucharest): " + zoneOffset);

        ZoneOffset zoneOffsetFromString = ZoneOffset.of("+02:00");
        System.out.println("\nZoneOffset from String: " + zoneOffsetFromString);
        // for example, use it to define an OffsetDateTime or an OffsetTime        
        OffsetTime offsetTime = OffsetTime.now(zoneOffsetFromString);
        OffsetDateTime offsetDateTime = OffsetDateTime.now(zoneOffsetFromString);
        System.out.println("OffsetTime from ZoneOffset of current date: " + offsetTime);
        System.out.println("OffsetDateTime from ZoneOffset of current date: " + offsetDateTime);

        ZoneOffset zoneOffsetFromHoursMinutes = ZoneOffset.ofHoursMinutes(8, 30);
        System.out.println("\nZoneOffset from hours and minutes: " + zoneOffsetFromHoursMinutes);

        ZoneOffset zoneOffsetFromOdt = offsetDateTime.getOffset();
        System.out.println("ZoneOffset from OffsetDateTime: " + zoneOffsetFromOdt);
    }
 
Example 4
Source File: OffsetDateTimeHandle.java    From alibaba-rsocket-broker with Apache License 2.0 4 votes vote down vote up
public OffsetDateTimeHandle(OffsetDateTime o) {
    this.dateTime = o.toLocalDateTime();
    this.offset = o.getOffset();
}
 
Example 5
Source File: OffsetDateTimeHandle.java    From joyrpc with Apache License 2.0 4 votes vote down vote up
@Override
public void wrap(final OffsetDateTime time) {
    this.dateTime = time.toLocalDateTime();
    this.offset = time.getOffset();
}
 
Example 6
Source File: PersistentOffsetDateTimeAsStringAndStringOffset.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
protected Object[] toConvertedColumns(OffsetDateTime value) {

    return new Object[] { value.toLocalDateTime(), value.getOffset() };
}