How to convert milliseconds to date in java?

2.23K viewsJava
0

Convert Milliseconds to a Date Format in Java, like as below as  M yyyy HH:mm:ss: SSS Z format.

Changed status to publish
Add a Comment
0

Use below snippet code convert milliseconds to a date format :

public Date convertMilliSecondsToDate(String milliSeconds,String dateFormat) {
long dateTimeInMilliSeconds = Long.parseLong(milliSeconds);
Calendar calendar=Calendar.getInstance();
calendar.setTimeInMillis(dateTimeInMilliSeconds);
DateFormat formatter = new SimpleDateFormat(dateFormat);
Date convertedDate=convertStrToDate(formatter.format(calendar.getTimeInMillis()),dateFormat);
return convertedDate;

}

Changed status to publish
Add a Comment
Write your answer.