[英]Why am I not getting correct human readable date and time value from my epoch value?
I want to bulk convert my epoch values into human readable date and time value. 我想将我的纪元值批量转换为人类可读的日期和时间值。 Taking a value 1342179766, I converted it on epoch-converter and got Fri, 13 Jul 2012 11:42:46 GMT as answer which I know is correct.
取值为1342179766,我在时代转换器上对其进行了转换,并得到格林尼治标准时间2012年7月13日星期五11:42:46作为星期五的答案,我知道这是正确的。 Now I used the java code provided on their site to convert it into date and time format but I am getting wrong answer.
现在,我使用他们网站上提供的Java代码将其转换为日期和时间格式,但答案却不正确。 Code:
码:
String date = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new java.util.Date (1342179766*1000));
System.out.println(date);
Output: 输出:
12/07/1969 09:40:02
I looked at other questions on stackoverflow but mostly this code is given everywhere. 我看了关于stackoverflow的其他问题,但大多数情况下此代码都给出了。 I found 2-3 other code but all of them are also giving me same output.
我发现了2-3个其他代码,但所有这些代码也都给了我相同的输出。
我猜您应该使用1342179766L*1000L
而不是1342179766*1000
。
Your issue comes from the fact that Java is trying to do integer multiplication on 1342179766*1000
and then convert it into a long. 您的问题来自Java试图在
1342179766*1000
上进行整数乘法, 然后将其转换为long的事实。 If you explicitly make this a long, then it works: 如果您明确地将其加长,那么它将起作用:
String date = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new java.util.Date (1342179766L*1000));
System.out.println(date);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.