I want to convert a timestamp in UTC, e.g. May 27, 2020, 22:35 (UTC) to epoch seconds. I will be hard coding the time in my code, so don't need to parse any string. I am using the Calendar class as follows:
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
calendar.set(2020, Calendar.MAY, 22, 22, 35);
calendar.getTimeInMillis();
The epoch time is correct to the second level, but the milliseconds part seems random on every run. Example run output:
Time : 1590618900110
Is there a way I can set the millisecond to zero in Calendar object, or a better option, possibly from the java.time framework?
Edit:
The following worked fine for me, since I am hardcoding the UTC time in code:
Instant instant = Instant.parse("2020-05-27T22:35:00.00Z");
long timeInMillisEpoch = instant.toEpochMilli();
Thank you, Ahmed.