Skip to content

Instantly share code, notes, and snippets.

@garbagetown
Created May 30, 2014 02:22
Show Gist options
  • Save garbagetown/ac2c4cde05409cac9972 to your computer and use it in GitHub Desktop.
Save garbagetown/ac2c4cde05409cac9972 to your computer and use it in GitHub Desktop.
Learning the useage of Date & Time API
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import static java.time.DayOfWeek.SATURDAY;
import static java.time.temporal.TemporalAdjusters.next;
import static java.time.temporal.TemporalAdjusters.nextOrSame;
public class Main {
private static final LocalTime time = LocalTime.of(0, 30);
public static void main(String[] args) {
LocalDateTime now = LocalDateTime.now();
LocalDate date = now.with(now.toLocalTime().compareTo(time) > 0 ? next(SATURDAY) : nextOrSame(SATURDAY)).toLocalDate();
LocalDateTime jojo = LocalDateTime.of(date, time);
System.out.printf("ジョジョまであと %d 分", Duration.between(now, jojo).toMinutes());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment