-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeProblems.java
More file actions
executable file
·32 lines (26 loc) · 1.13 KB
/
Copy pathTimeProblems.java
File metadata and controls
executable file
·32 lines (26 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
public class TimeProblems {
public static int countFridayThirteens(LocalDate startDate, LocalDate endDate){
int friThirteens = 0;
for(LocalDate ldt = startDate; !ldt.isAfter(endDate) ;ldt = ldt.plusDays(1)){
if( (ldt.getDayOfWeek() == DayOfWeek.FRIDAY) && ( ldt.getDayOfMonth() == 13)){
friThirteens++;
}
}
return friThirteens;
}
public static String dayAfterSeconds(LocalDateTime timeHere, long seconds){
LocalDateTime futureDateTime = timeHere.plusSeconds(seconds);
String getDayOfWeek = futureDateTime.getDayOfWeek().name();
return getDayOfWeek ;
}
public static int whatHourIsItThere(LocalDateTime timeHere, String here, String there){
ZonedDateTime zdtHere = timeHere.atZone(ZoneId.of(here));
ZonedDateTime zdtThere = zdtHere.withZoneSameInstant(ZoneId.of(there));
return zdtThere.getHour();
}
}