gpt4 book ai didi

JAVA/GWT - DateFormat 恢复为 1/15/1970

转载 作者:行者123 更新时间:2023-12-02 00:50:20 25 4
gpt4 key购买 nike

我试图将时间戳解析为人类可读的日期字符串,但是,我不断得到 1/15/1970 作为返回。

//Here is my formatter
DateTimeFormat Format = DateTimeFormat.getFormat("MM/dd/yyyy");

//Here is my timestamp - SHOULD BE AUGUST 16TH, 2010
String date = "1281966439";

//Here is where I create the date, and format it
int intDate = Integer.parseInt(date);
Date eventDate = new Date(intDate);
String eventDateFinal = Format.format(eventDate);

//In this alert, I get 1/15/1970
Window.alert(eventFinal);

我以为我可能使用毫秒而不是秒,但是当我以毫秒为单位输入值时,出现异常。

有人遇到过这个问题吗?

最佳答案

Date 构造函数需要一个 long,而不是 int,它是自纪元以来的毫秒数。

//Here is my formatter
DateTimeFormat Format = DateTimeFormat.getFormat("MM/dd/yyyy");

//Here is my timestamp - SHOULD BE AUGUST 16TH, 2010
String date = "1281966439000";

//Here is where I create the date, and format it
long longDate = Long.parseLong(date);
Date eventDate = new Date(longDate);
String eventDateFinal = Format.format(eventDate);

//In this alert, I get 1/15/1970
Window.alert(eventFinal);

关于JAVA/GWT - DateFormat 恢复为 1/15/1970,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3495867/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com