How to convert ( round ) epoch Time to nearest hou

2019-09-10 01:46发布

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条回答
男人必须洒脱
2楼-- · 2019-09-10 02:38

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.

查看更多
登录 后发表回答