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());
Pergunta
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?
Solução
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());
Outras dicas
I suppose you should multiply your input with 1000 (UNIX timestamp in seconds, but Java j.u.Date in milliseconds).
Edit:
Oh another mistake in your code: The pattern symbol should be d, not D (day-of-year).