【发布时间】:2019-01-10 01:27:31
【问题描述】:
“1.5332445E9”如何转换为日期和时间?
到现在我都试过了
private String getDate(long time) {
Date date = new Date(time);
return Utils.getFormattedDate(date, "dd/MM/yyyy HH:mm:ss a");
}
public static String getFormattedDate(Date date, String desiredFormat) {
DateFormat dateFormat = new SimpleDateFormat(desiredFormat);
dateFormat.format(date);
return dateFormat.format(date);
}
任何帮助将不胜感激。
【问题讨论】:
-
感谢@Selvin,它就像一个魅力......简单而优雅
-
顺便说一句,
Date类早已过时且设计不佳,而SimpleDateFormat是出了名的麻烦。您可能要考虑改用java.time, the modern Java date and time API,。在不是全新的 Android 上通过 the ThreeTenABP library 使用它。
标签: android android-studio datetime simpledateformat date-format