Created
January 11, 2016 20:32
-
-
Save jokamjohn/fd34b1064085b4c18e2b to your computer and use it in GitHub Desktop.
This file contains hidden or 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.LocalDateTime; | |
| import java.time.temporal.ChronoUnit; | |
| public class DateTimeAPIStateless | |
| { | |
| public static void main( String[] args ) | |
| { | |
| LocalDateTime timeInThePast = LocalDateTime.now().withDayOfMonth( 5 ).withYear( 2005 ); | |
| System.out.println( "timeInThePast: " + timeInThePast ); | |
| LocalDateTime moreInThePast = timeInThePast.minusWeeks( 2 ).plus( 3, ChronoUnit.DAYS ); | |
| // operations do not affect the variable, is thread safe and stateless | |
| System.out.println( "timeInThePast: " + timeInThePast ); | |
| // a new variable is returned | |
| System.out.println( "moreInThePast: " + moreInThePast ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment