Created
May 30, 2014 02:22
-
-
Save garbagetown/ac2c4cde05409cac9972 to your computer and use it in GitHub Desktop.
Learning the useage of Date & Time API
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.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