我想将长值转换为格式化时间。 我使用的代码:
long startTimeInSeconds = 60*60*1000*sH + 60*1000*sM + sS*1000 + sL;
SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm:ss,SSS");
Date start= new Date(SU.startTime);
StartTime = dateFormat.format(start);
这里sH
sM
..是字符串中的小时分钟..,格式是这样的:“hh:mm:ss,SSS”
。
SU.startTime
是 startTimeInSeconds
。
StartTime
是一个字符串。
当我显示StartTime
时,它没有给我正确的时间。
例如,当 startTimeInSeconds
为 2510823
时,它必须为 0:41:50,823
但我得到 1:41:50,823
。
我不知道我做错了什么,如果我显示小时分钟......像这样:
int hours = (int) (SU.startTime / (60 * 60 * 1000));
然后我得到正确的值。
有谁知道这个问题的解决办法吗?
最佳答案
我的猜测是,您在英国或法国,1970 年 1 月 1 日的时区是 GMT+1。如果您将时区设置为“GMT”,则不会出现此问题。
关于java - 将毫秒转换为日期时间会给出错误的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14520044/