我有这样的时间戳(形成json响应):
“ /日期(1479974400000-0800)/”
我正在尝试使用此功能将时间戳转换为日期:
public String getDate() {
Calendar cal = Calendar.getInstance(Locale.ENGLISH);
cal.setTimeInMillis(time);
String date = DateFormat.format("dd-MM-yyyy", cal).toString();
return date;
}
如何将此时间戳转换为日期格式?
解决方案对我来说是这样的:
String str = obj.getString("eventdate").replaceAll("\\D+", "");
String upToNCharacters = str.substring(0, Math.min(str.length(), 13));
DateFormat timeZoneFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
timeZoneFormat.setTimeZone(TimeZone.getTimeZone("GMT-8"));
Date time = new java.util.Date(Long.parseLong(upToNCharacters));
// System.out.println(time);
model.setDate(String.valueOf(timeZoneFormat.format(time)));
在需要的地方使用时间变量
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句