- 英文时间转中文格式
String created_at = "Sun Mar 15 06:27:54 +0000 2020";
SimpleDateFormat sfEnd = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sfStart = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH);
String reply_time = sfEnd.format(sfStart.parse(created_at));
- 时间戳转字符串
private String timeStamp2Date(String seconds, String format) {
if (seconds == null || seconds.isEmpty() || seconds.equals("null")) {
return "";
}
if (format == null || format.isEmpty()) {
format = "yyyy-MM-dd HH:mm:ss";
}
SimpleDateFormat sdf = new SimpleDateFormat(format);
Long timeStamp if (seconds.length() == 13) {
timeStamp = Long.valueOf(seconds)
} else if (seconds.length() == 10) {
timeStamp = Long.valueOf(seconds + "000")
} else {
throw new Exception("时间戳格式不正确!!!")
} return sdf.format(new Date(timeStamp));
}
持续更新中…