【发布时间】:2020-08-17 13:46:59
【问题描述】:
所以我在将整数日期时间格式转换为 Java 中的普通日期时间格式时遇到了这个问题。 我有这个变量 int DateTime,例如它是:“/Date(1484956800000)/”。我正在尝试将其转换为正常的日期时间并将其显示在屏幕上...
我试过这样..
String dateAsText = new SimpleDateFormat("MM-dd HH:mm")
.format(new Date(Integer.parseInt(deals.getDate_time()) * 1000L));
// setting my textView with the string dateAsText
holder.Time.setText(dateAsText);
【问题讨论】:
-
看来您的 int/long 值 (1484956800000) 已经是毫秒分辨率的时间戳。尝试转换它而不先乘以 1000L。
-
@ThomasKläger 我删除了 1000L ,但同样的问题..,
-
同样的问题 — 哪个问题,我想你忘了告诉我们? I downvoted because without a proper and precise problem description we cannot help you.
-
抱歉,我错过了那个:
Integer.parseInt(deals.getDate_time())会为 1484956800000 抛出NumberFormatException,因为 1484956800000 不适合整数范围。您还必须将其替换为Long.parseLong(deals.getDate_time())
标签: java android-studio date datetime datetime-format