Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save jokamjohn/ebe10b01aa3ad1c2695a to your computer and use it in GitHub Desktop.
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
public class TemporalAdjustersExamples
{
public static void main( String[] args )
{
/* using adjuster is possible to adjust a given date */
LocalDate now = LocalDate.now();
System.out.println( "now " + now );
DayOfWeek dayOfWeek = now.getDayOfWeek();
System.out.println( "day of week " + dayOfWeek );
LocalDate adjusted = now.with( TemporalAdjusters.lastDayOfMonth() );
System.out.println( "now with last day of month " + adjusted );
System.out.println( "now " + now );
System.out.println( "now with last friday in month "
+ now.with( TemporalAdjusters.lastInMonth( DayOfWeek.FRIDAY ) ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment