Java转换长到日期? [英] Java Convert Long to Date?

查看:133
本文介绍了Java转换长到日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有从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);

这里显示


Sun Aug 31 20:00:00 GMT-04:00 2008

Sun Aug 31 20:00:00 GMT-04:00 2008

这篇关于Java转换长到日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆