Is it possible to create a java.util.Date
object that is guaranteed to be UTC and at a specific time in the past, like an hour ago or a day ago, and is this a g
You can achieve this using the java.time
package, as follows:
LocalDateTime localDateTime = LocalDateTime.now(ZoneOffset.UTC).minusHours(4);
Date date = Date.from(localDateTime.atZone(ZoneOffset.UTC).toInstant());
Gives the following output:
2018-01-31T14:58:28.908
Wed Jan 31 20:28:28 IST 2018 //20:28:28 IST is 14:58:28 UTC
Which is correctly 4+5:30
hours behind my current time - Asia/Kolkata ZoneId
.