Created
February 7, 2015 01:58
-
-
Save LB--/3064de856857ad95753d to your computer and use it in GitHub Desktop.
Java 8 Time Library - just keeping this for reference
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 java.time.Instant; | |
import java.time.LocalDateTime; | |
import java.time.Month; | |
import java.time.ZoneId; | |
import java.time.ZoneOffset; | |
import java.time.temporal.ChronoField; | |
class j8time | |
{ | |
public static void main (String[] args) throws Throwable | |
{ | |
//day before name changes | |
System.out.println(LocalDateTime.ofInstant(Instant.EPOCH, ZoneId.systemDefault()) | |
.with(ChronoField.YEAR, 2015) | |
.with(ChronoField.MONTH_OF_YEAR, Month.FEBRUARY.getValue()) | |
.with(ChronoField.DAY_OF_MONTH, 3) | |
.toInstant(ZoneOffset.UTC) | |
.toEpochMilli()/1000L); | |
//time I changed my name | |
System.out.println(Instant.ofEpochMilli(1423055984000L)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment