Created
August 31, 2016 06:25
-
-
Save ikhoon/7c023bbc65078e06598c769978b76b2b to your computer and use it in GitHub Desktop.
Java8 Time API 기능 비교
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.junit.Test; | |
import java.time.Instant; | |
import java.time.OffsetDateTime; | |
import java.time.ZonedDateTime; | |
import java.time.format.DateTimeParseException; | |
public class Java8TimeTest { | |
private String instantFormat = "2007-12-03T10:14:30.000Z"; | |
private String offsetTimeZoneFormat = "2007-12-03T10:15:30+01:00"; | |
private String zoneTimezoneFormat = "2007-12-03T10:15:30+01:00[Europe/Paris]"; | |
@Test(expected = DateTimeParseException.class) | |
public void testInstant() throws Exception { | |
System.out.println(Instant.parse(instantFormat)); | |
// java.time.format.DateTimeParseException: Text '2007-12-03T10:15:30+01:00' could not be parsed at index 19 | |
System.out.println(Instant.parse(offsetTimeZoneFormat)); | |
// java.time.format.DateTimeParseException: Text '2007-12-03T10:15:30+01:00[Europe/Paris]' could not be parsed at index 19 | |
System.out.println(Instant.parse(zoneTimezoneFormat)); | |
} | |
@Test(expected = DateTimeParseException.class) | |
public void testOffsetTime() throws Exception { | |
System.out.println(OffsetDateTime.parse(instantFormat)); | |
System.out.println(OffsetDateTime.parse(offsetTimeZoneFormat)); | |
// java.time.format.DateTimeParseException: Text '2007-12-03T10:15:30+01:00[Europe/Paris]' could not be parsed, unparsed text found at index 2 | |
System.out.println(OffsetDateTime.parse(zoneTimezoneFormat)); | |
} | |
@Test | |
public void testZoneTime() throws Exception { | |
System.out.println(ZonedDateTime.parse(instantFormat)); | |
System.out.println(ZonedDateTime.parse(offsetTimeZoneFormat)); | |
System.out.println(ZonedDateTime.parse(zoneTimezoneFormat)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment