本文介绍了在Java中将Long转换为Date将返回1970年的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有从Web服务下载的长值列表(例如:1220227200,1220832000,1221436800 ...)。我必须把它转换成日期。不幸的是这样,例如:

I have list with long values (for example: 1220227200, 1220832000, 1221436800...) which I downloaded from web service. I must convert it to Dates. Unfortunately this way, for example:

Date d = new Date(1220227200);

返回1970年1月1日。有人知道另一种方法正确转换它吗?

returns 1 Jan 1970. Anyone know another way to convert it correctly?

推荐答案

(单击链接!)接受时间为 long 毫秒,而不是秒。你需要将它乘以1000,并确保你提供它 long

The Date constructor (click the link!) accepts the time as long in milliseconds, not seconds. You need to multiply it by 1000 and make sure that you supply it as long.

Date d = new Date(1220227200L * 1000);

这里显示

这篇关于在Java中将Long转换为Date将返回1970年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 10:03