Reputation: 543
Given a month (for March 3, for September 9, etc) and a year (2018, etc) I want to be able to get the epoch time value of two exact time-dates :
Thanks in advance
Upvotes: 1
Views: 68
Reputation: 521194
For the last instant of the current month, you may simply subtract one second from the midnight of the start of the preceding month. Here is a Java 8 option:
LocalDate start = LocalDate.of(2018, 5, 1);
LocalDate end = LocalDate.of(2018, 6, 1);
ZoneId zoneId = ZoneId.systemDefault();
long e1 = start.atStartOfDay(zoneId).toEpochSecond();
long e2 = end.atStartOfDay(zoneId).toEpochSecond() - 1L;
Upvotes: 2