Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: epoch date to MM/DD/YYYY

My time: 1386696238

My code:

Date date = new Date(Long.parseLong(currentNotification.getDate_created()));
        SimpleDateFormat formatter = new SimpleDateFormat("MM/DD/yyyy", Locale.getDefault());
        String dateString = formatter.format(date);

My result: 1/16/1970

Desired result: 12/10/2013

What am I doing wrong?

like image 333
CQM Avatar asked Aug 09 '26 02:08

CQM


1 Answers

Your value is in seconds, so you need to multiply it by 1000.

Also, DD is day of year, you want dd:

SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy", Locale.getDefault());
like image 186
Keppil Avatar answered Aug 10 '26 15:08

Keppil