Java 爪哇:纪元日期至年月日
我的时间:1386696238 我的代码:Java 爪哇:纪元日期至年月日,java,date,simpledateformat,epoch,Java,Date,Simpledateformat,Epoch,我的时间:1386696238 我的代码: Date date = new Date(Long.parseLong(currentNotification.getDate_created())); SimpleDateFormat formatter = new SimpleDateFormat("MM/DD/yyyy", Locale.getDefault()); String dateString = formatter.format(date); 我的结果
Date date = new Date(Long.parseLong(currentNotification.getDate_created()));
SimpleDateFormat formatter = new SimpleDateFormat("MM/DD/yyyy", Locale.getDefault());
String dateString = formatter.format(date);
我的结果:1/16/1970
预期结果:12/10/2013
我做错了什么?我想您应该将输入乘以1000(UNIX时间戳以秒为单位,Java j.u.Date以毫秒为单位) 编辑:
哦,代码中的另一个错误:模式符号应该是d,而不是d(一年中的某一天)。您的值以秒为单位,因此需要将其乘以1000 另外,
DD
是一年中的一天,您需要DD
:
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy", Locale.getDefault());
月日:
d
(小写)@Reimeus乘以1000在我的应用程序中为我提供了正确的日期java.util
Date-Time API及其格式化API,SimpleDataFormat
已经过时且容易出错。建议完全停止使用,并切换到。使用现代日期时间API检查答案。