How to transform currentTimeMillis to a readable date format? [duplicate]
Solution 1:
It will work.
long yourmilliseconds = System.currentTimeMillis();
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");
Date resultdate = new Date(yourmilliseconds);
System.out.println(sdf.format(resultdate));
Solution 2:
There is a simpler way in Android
DateFormat.getInstance().format(currentTimeMillis);
Moreover, Date is deprecated, so use DateFormat class.
DateFormat.getDateInstance().format(new Date(0));
DateFormat.getDateTimeInstance().format(new Date(0));
DateFormat.getTimeInstance().format(new Date(0));
The above three lines will give:
Dec 31, 1969
Dec 31, 1969 4:00:00 PM
4:00:00 PM 12:00:00 AM