首页 > 编程知识 正文

java将时间戳转化为时间格式,java时间戳转换成时间

时间:2023-05-04 19:47:24 阅读:232592 作者:1028

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

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

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

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。