How to convert ( round ) epoch Time to nearest hour and day wrt IST (in Java)

非 Y 不嫁゛ 提交于 2019-12-13 06:01:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!