java时间戳转换日期格式,如何在Java中将时间戳转换为日期格式

I have a time stamp like this(form a json response) :

"/Date(1479974400000-0800)/"

I'm trying this function to convert time stamp into date:

public String getDate() {

Calendar cal = Calendar.getInstance(Locale.ENGLISH);

cal.setTimeInMillis(time);

String date = DateFormat.format("dd-MM-yyyy", cal).toString();

return date;

}

How to convert this Timestamp into Date format?

解决方案

The solution works

for me is like this:

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)));

Use time variable where you want

你可能感兴趣的:(java时间戳转换日期格式)