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

The following examples show how to use java.time.OffsetDateTime#toZonedDateTime() . 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: TCKZoneOffset.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void test_adjustInto_OffsetDateTime() {
    ZoneOffset base = ZoneOffset.ofHoursMinutesSeconds(1, 1, 1);
    for (int i=-18; i<=18; i++) {
        OffsetDateTime offsetDateTime_target = OffsetDateTime.of(LocalDate.of(1909, 2, 2), LocalTime.of(10, 10, 10), ZoneOffset.ofHours(i));
        OffsetDateTime offsetDateTime_result = (OffsetDateTime)base.adjustInto(offsetDateTime_target);
        assertEquals(base, offsetDateTime_result.getOffset());

        //Do not change offset of ZonedDateTime after adjustInto()
        ZonedDateTime zonedDateTime_target = offsetDateTime_target.toZonedDateTime();
        ZonedDateTime zonedDateTime_result = (ZonedDateTime)(base.adjustInto(zonedDateTime_target));
        assertEquals(zonedDateTime_target.getOffset(), zonedDateTime_result.getOffset());
    }
}
 
Example 2
Source File: TCKZoneOffset.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_adjustInto_OffsetDateTime() {
    ZoneOffset base = ZoneOffset.ofHoursMinutesSeconds(1, 1, 1);
    for (int i=-18; i<=18; i++) {
        OffsetDateTime offsetDateTime_target = OffsetDateTime.of(LocalDate.of(1909, 2, 2), LocalTime.of(10, 10, 10), ZoneOffset.ofHours(i));
        OffsetDateTime offsetDateTime_result = (OffsetDateTime)base.adjustInto(offsetDateTime_target);
        assertEquals(base, offsetDateTime_result.getOffset());

        //Do not change offset of ZonedDateTime after adjustInto()
        ZonedDateTime zonedDateTime_target = offsetDateTime_target.toZonedDateTime();
        ZonedDateTime zonedDateTime_result = (ZonedDateTime)(base.adjustInto(zonedDateTime_target));
        assertEquals(zonedDateTime_target.getOffset(), zonedDateTime_result.getOffset());
    }
}
 
Example 3
Source File: TCKZoneOffset.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_adjustInto_OffsetDateTime() {
    ZoneOffset base = ZoneOffset.ofHoursMinutesSeconds(1, 1, 1);
    for (int i=-18; i<=18; i++) {
        OffsetDateTime offsetDateTime_target = OffsetDateTime.of(LocalDate.of(1909, 2, 2), LocalTime.of(10, 10, 10), ZoneOffset.ofHours(i));
        OffsetDateTime offsetDateTime_result = (OffsetDateTime)base.adjustInto(offsetDateTime_target);
        assertEquals(base, offsetDateTime_result.getOffset());

        //Do not change offset of ZonedDateTime after adjustInto()
        ZonedDateTime zonedDateTime_target = offsetDateTime_target.toZonedDateTime();
        ZonedDateTime zonedDateTime_result = (ZonedDateTime)(base.adjustInto(zonedDateTime_target));
        assertEquals(zonedDateTime_target.getOffset(), zonedDateTime_result.getOffset());
    }
}
 
Example 4
Source File: TCKZoneOffset.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_adjustInto_OffsetDateTime() {
    ZoneOffset base = ZoneOffset.ofHoursMinutesSeconds(1, 1, 1);
    for (int i=-18; i<=18; i++) {
        OffsetDateTime offsetDateTime_target = OffsetDateTime.of(LocalDate.of(1909, 2, 2), LocalTime.of(10, 10, 10), ZoneOffset.ofHours(i));
        OffsetDateTime offsetDateTime_result = (OffsetDateTime)base.adjustInto(offsetDateTime_target);
        assertEquals(base, offsetDateTime_result.getOffset());

        //Do not change offset of ZonedDateTime after adjustInto()
        ZonedDateTime zonedDateTime_target = offsetDateTime_target.toZonedDateTime();
        ZonedDateTime zonedDateTime_result = (ZonedDateTime)(base.adjustInto(zonedDateTime_target));
        assertEquals(zonedDateTime_target.getOffset(), zonedDateTime_result.getOffset());
    }
}
 
Example 5
Source File: TCKZoneOffset.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_adjustInto_OffsetDateTime() {
    ZoneOffset base = ZoneOffset.ofHoursMinutesSeconds(1, 1, 1);
    for (int i=-18; i<=18; i++) {
        OffsetDateTime offsetDateTime_target = OffsetDateTime.of(LocalDate.of(1909, 2, 2), LocalTime.of(10, 10, 10), ZoneOffset.ofHours(i));
        OffsetDateTime offsetDateTime_result = (OffsetDateTime)base.adjustInto(offsetDateTime_target);
        assertEquals(base, offsetDateTime_result.getOffset());

        //Do not change offset of ZonedDateTime after adjustInto()
        ZonedDateTime zonedDateTime_target = offsetDateTime_target.toZonedDateTime();
        ZonedDateTime zonedDateTime_result = (ZonedDateTime)(base.adjustInto(zonedDateTime_target));
        assertEquals(zonedDateTime_target.getOffset(), zonedDateTime_result.getOffset());
    }
}
 
Example 6
Source File: TCKZoneOffset.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_adjustInto_OffsetDateTime() {
    ZoneOffset base = ZoneOffset.ofHoursMinutesSeconds(1, 1, 1);
    for (int i=-18; i<=18; i++) {
        OffsetDateTime offsetDateTime_target = OffsetDateTime.of(LocalDate.of(1909, 2, 2), LocalTime.of(10, 10, 10), ZoneOffset.ofHours(i));
        OffsetDateTime offsetDateTime_result = (OffsetDateTime)base.adjustInto(offsetDateTime_target);
        assertEquals(base, offsetDateTime_result.getOffset());

        //Do not change offset of ZonedDateTime after adjustInto()
        ZonedDateTime zonedDateTime_target = offsetDateTime_target.toZonedDateTime();
        ZonedDateTime zonedDateTime_result = (ZonedDateTime)(base.adjustInto(zonedDateTime_target));
        assertEquals(zonedDateTime_target.getOffset(), zonedDateTime_result.getOffset());
    }
}
 
Example 7
Source File: TCKZoneOffset.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_adjustInto_OffsetDateTime() {
    ZoneOffset base = ZoneOffset.ofHoursMinutesSeconds(1, 1, 1);
    for (int i=-18; i<=18; i++) {
        OffsetDateTime offsetDateTime_target = OffsetDateTime.of(LocalDate.of(1909, 2, 2), LocalTime.of(10, 10, 10), ZoneOffset.ofHours(i));
        OffsetDateTime offsetDateTime_result = (OffsetDateTime)base.adjustInto(offsetDateTime_target);
        assertEquals(base, offsetDateTime_result.getOffset());

        //Do not change offset of ZonedDateTime after adjustInto()
        ZonedDateTime zonedDateTime_target = offsetDateTime_target.toZonedDateTime();
        ZonedDateTime zonedDateTime_result = (ZonedDateTime)(base.adjustInto(zonedDateTime_target));
        assertEquals(zonedDateTime_target.getOffset(), zonedDateTime_result.getOffset());
    }
}
 
Example 8
Source File: TCKZoneOffset.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_adjustInto_OffsetDateTime() {
    ZoneOffset base = ZoneOffset.ofHoursMinutesSeconds(1, 1, 1);
    for (int i=-18; i<=18; i++) {
        OffsetDateTime offsetDateTime_target = OffsetDateTime.of(LocalDate.of(1909, 2, 2), LocalTime.of(10, 10, 10), ZoneOffset.ofHours(i));
        OffsetDateTime offsetDateTime_result = (OffsetDateTime)base.adjustInto(offsetDateTime_target);
        assertEquals(base, offsetDateTime_result.getOffset());

        //Do not change offset of ZonedDateTime after adjustInto()
        ZonedDateTime zonedDateTime_target = offsetDateTime_target.toZonedDateTime();
        ZonedDateTime zonedDateTime_result = (ZonedDateTime)(base.adjustInto(zonedDateTime_target));
        assertEquals(zonedDateTime_target.getOffset(), zonedDateTime_result.getOffset());
    }
}
 
Example 9
Source File: TCKZoneOffset.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_adjustInto_OffsetDateTime() {
    ZoneOffset base = ZoneOffset.ofHoursMinutesSeconds(1, 1, 1);
    for (int i=-18; i<=18; i++) {
        OffsetDateTime offsetDateTime_target = OffsetDateTime.of(LocalDate.of(1909, 2, 2), LocalTime.of(10, 10, 10), ZoneOffset.ofHours(i));
        OffsetDateTime offsetDateTime_result = (OffsetDateTime)base.adjustInto(offsetDateTime_target);
        assertEquals(base, offsetDateTime_result.getOffset());

        //Do not change offset of ZonedDateTime after adjustInto()
        ZonedDateTime zonedDateTime_target = offsetDateTime_target.toZonedDateTime();
        ZonedDateTime zonedDateTime_result = (ZonedDateTime)(base.adjustInto(zonedDateTime_target));
        assertEquals(zonedDateTime_target.getOffset(), zonedDateTime_result.getOffset());
    }
}
 
Example 10
Source File: TCKZoneOffset.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_adjustInto_OffsetDateTime() {
    ZoneOffset base = ZoneOffset.ofHoursMinutesSeconds(1, 1, 1);
    for (int i=-18; i<=18; i++) {
        OffsetDateTime offsetDateTime_target = OffsetDateTime.of(LocalDate.of(1909, 2, 2), LocalTime.of(10, 10, 10), ZoneOffset.ofHours(i));
        OffsetDateTime offsetDateTime_result = (OffsetDateTime)base.adjustInto(offsetDateTime_target);
        assertEquals(base, offsetDateTime_result.getOffset());

        //Do not change offset of ZonedDateTime after adjustInto()
        ZonedDateTime zonedDateTime_target = offsetDateTime_target.toZonedDateTime();
        ZonedDateTime zonedDateTime_result = (ZonedDateTime)(base.adjustInto(zonedDateTime_target));
        assertEquals(zonedDateTime_target.getOffset(), zonedDateTime_result.getOffset());
    }
}
 
Example 11
Source File: TCKZoneOffset.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_adjustInto_OffsetDateTime() {
    ZoneOffset base = ZoneOffset.ofHoursMinutesSeconds(1, 1, 1);
    for (int i=-18; i<=18; i++) {
        OffsetDateTime offsetDateTime_target = OffsetDateTime.of(LocalDate.of(1909, 2, 2), LocalTime.of(10, 10, 10), ZoneOffset.ofHours(i));
        OffsetDateTime offsetDateTime_result = (OffsetDateTime)base.adjustInto(offsetDateTime_target);
        assertEquals(base, offsetDateTime_result.getOffset());

        //Do not change offset of ZonedDateTime after adjustInto()
        ZonedDateTime zonedDateTime_target = offsetDateTime_target.toZonedDateTime();
        ZonedDateTime zonedDateTime_result = (ZonedDateTime)(base.adjustInto(zonedDateTime_target));
        assertEquals(zonedDateTime_target.getOffset(), zonedDateTime_result.getOffset());
    }
}
 
Example 12
Source File: TCKZoneOffset.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_adjustInto_OffsetDateTime() {
    ZoneOffset base = ZoneOffset.ofHoursMinutesSeconds(1, 1, 1);
    for (int i=-18; i<=18; i++) {
        OffsetDateTime offsetDateTime_target = OffsetDateTime.of(LocalDate.of(1909, 2, 2), LocalTime.of(10, 10, 10), ZoneOffset.ofHours(i));
        OffsetDateTime offsetDateTime_result = (OffsetDateTime)base.adjustInto(offsetDateTime_target);
        assertEquals(base, offsetDateTime_result.getOffset());

        //Do not change offset of ZonedDateTime after adjustInto()
        ZonedDateTime zonedDateTime_target = offsetDateTime_target.toZonedDateTime();
        ZonedDateTime zonedDateTime_result = (ZonedDateTime)(base.adjustInto(zonedDateTime_target));
        assertEquals(zonedDateTime_target.getOffset(), zonedDateTime_result.getOffset());
    }
}
 
Example 13
Source File: TCKZoneOffset.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_adjustInto_OffsetDateTime() {
    ZoneOffset base = ZoneOffset.ofHoursMinutesSeconds(1, 1, 1);
    for (int i=-18; i<=18; i++) {
        OffsetDateTime offsetDateTime_target = OffsetDateTime.of(LocalDate.of(1909, 2, 2), LocalTime.of(10, 10, 10), ZoneOffset.ofHours(i));
        OffsetDateTime offsetDateTime_result = (OffsetDateTime)base.adjustInto(offsetDateTime_target);
        assertEquals(base, offsetDateTime_result.getOffset());

        //Do not change offset of ZonedDateTime after adjustInto()
        ZonedDateTime zonedDateTime_target = offsetDateTime_target.toZonedDateTime();
        ZonedDateTime zonedDateTime_result = (ZonedDateTime)(base.adjustInto(zonedDateTime_target));
        assertEquals(zonedDateTime_target.getOffset(), zonedDateTime_result.getOffset());
    }
}
 
Example 14
Source File: DateConverterImpl.java    From sfg-blog-posts with GNU General Public License v3.0 4 votes vote down vote up
public ZonedDateTime convertToZonedDateTime() {
    OffsetDateTime offsetDateTime = OffsetDateTime.now();
    ZonedDateTime zonedDateTime1 = offsetDateTime.toZonedDateTime();
    System.out.println(zonedDateTime1);
    return zonedDateTime1;
}
 
Example 15
Source File: DateTimeConverters.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public ZonedDateTime convert(OffsetDateTime source) {
	return source.toZonedDateTime();
}
 
Example 16
Source File: DateTimeConverters.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ZonedDateTime convert(OffsetDateTime source) {
	return source.toZonedDateTime();
}
 
Example 17
Source File: PDTFactory.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Nullable
public static ZonedDateTime createZonedDateTime (@Nullable final OffsetDateTime aODT)
{
  return aODT == null ? null : aODT.toZonedDateTime ();
}
 
Example 18
Source File: DateTimeConverters.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public ZonedDateTime convert(OffsetDateTime source) {
	return source.toZonedDateTime();
}
 
Example 19
Source File: DateTimeConverters.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public ZonedDateTime convert(OffsetDateTime source) {
	return source.toZonedDateTime();
}
 
Example 20
Source File: PDTWebDateHelper.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Parses a Date out of a String with a date in W3C date-time format or in a
 * RFC822 format.
 *
 * @param sDate
 *        string to parse for a date.
 * @return the Date represented by the given W3C date-time string. It returns
 *         <b>null</b> if it was not possible to parse the given string into a
 *         Date.
 */
@Nullable
public static ZonedDateTime getDateTimeFromW3COrRFC822 (@Nullable final String sDate)
{
  final OffsetDateTime aDateTime = getDateTimeFromW3C (sDate);
  if (aDateTime != null)
    return aDateTime.toZonedDateTime ();

  return getDateTimeFromRFC822 (sDate);
}