如何将epoch时间转换为最近的小时和星期几IST(Java) [英] How to convert ( round ) epoch Time to nearest hour and day wrt IST (in Java)
问题描述
我有时间以纪元格式(作为Java long变量)。
I have time in epoch format (as Java long variable).
我想将其转换为与印度标准时间(英国标准时间)相近的小时和日期( IST)。
I want to convert it to nearest hour as well as day with respect to Indian Standard Time (IST).
例如,如果纪元时间为1372618032000(2013/7/1/12 12:17:12 IST),那么我想获得1372620600000(7 / 1/2013 1:00 00 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).
类似地,用于四舍五入。
我想获得1370703400(美国标准时间2013年7月2日12:00:00)。 [第二天开始。]
Similarly for day rounding. I want to get 1372703400 (7/2/2013 12:00:00 AM IST). [Starting of the next day.]
我浏览了一些有关Java Date,Java Calendar,Apache DateUtils和JodaTime的文档。
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 ?
注意:我想就IST。
推荐答案
当然,您不会获得实现此目标的方法。
Certainly, you won't get a method to accomplish this.
为什么不使用 java.util.Calendar
的方法 get(int字段)
和 set(int字段,int值)
。我很肯定可以使用这些方法和一些取整逻辑来完成。
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.
这篇关于如何将epoch时间转换为最近的小时和星期几IST(Java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!