问题
I have time in epoch format (as Java long variable).
I want to convert it to nearest hour as well as day with respect to Indian Standard Time (IST).
For example, if the epoch time is 1372618032000 (7/1/2013 12:17:12 AM IST), then i want to get 1372620600000 (7/1/2013 1:00:00 AM IST).
Similarly for day rounding. I want to get 1372703400 (7/2/2013 12:00:00 AM IST). [Starting of the next day.]
I have gone through some documentation of Java Date, Java Calendar, Apache DateUtils, and JodaTime.
But i am not able to figure out what is the correct and best way to do this ?
NOTE: I want to round with respect to IST.
回答1:
Certainly, you won't get a method to accomplish this.
Why not use java.util.Calendar's methods get(int field) and set(int field, int value). I'm positive that it can be done with these methods and a bit of rounding logic.
来源:https://stackoverflow.com/questions/17393764/how-to-convert-round-epoch-time-to-nearest-hour-and-day-wrt-ist-in-java