Skip to content

Instantly share code, notes, and snippets.

@jokamjohn
Created January 11, 2016 20:32
Show Gist options
  • Select an option

  • Save jokamjohn/fd34b1064085b4c18e2b to your computer and use it in GitHub Desktop.

Select an option

Save jokamjohn/fd34b1064085b4c18e2b to your computer and use it in GitHub Desktop.
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