0

Following is the date stored in the database:

2014-05-23 13:34:32

The date column is a timestamp, and the value returned in the JSON object is:

 1390421072000

When I try to convert this back to a date with the following it gives a wrong date - 2014-01-22T20:04:34.000Z:

log.logDateTime  = new Date(log.logDateTime);

I guess this has something to do with the format or locale, in that case how do I do the correct conversion? I want to get the date as it is in the DB.

In server side, I do a conversion as follows:

df = new SimpleDateFormat("yyyyy-mm-dd hh:mm:ss");
Date logDate = (Date) df.parseObject(df.format(lg.getTime()));
devC
  • 1,266
  • 4
  • 22
  • 48
  • `1390421072000ms` from `1970-01-01 00:00:00` = `Wed Jan 22 20:04:32 UTC 2014`. Is there some conversion etc. in between that could cause the problem? – heikkim Sep 03 '14 at 11:04
  • Updated the question with some server side formatting i'm doing. – devC Sep 03 '14 at 11:08

1 Answers1

1

Your dateformat is incorrect. It should be:

df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

The mm stands for minutes, MM for months. Additionally you want to use HH which stands for 24h time.

heikkim
  • 2,835
  • 2
  • 21
  • 33
  • thanks, this halfway solved my problem. But still the date is displayed as 2014-05-23T08:04:32.000Z. How do I format it to show as 2014-05-23 13:34:32? – devC Sep 03 '14 at 11:20
  • In Javascript? There's no out-of-the-box way, but the question has been answered here: http://stackoverflow.com/questions/3552461/how-to-format-javascript-date – heikkim Sep 03 '14 at 11:28
  • Yes.. the time is incorrect because you're using `hh`, use `HH`. – heikkim Sep 03 '14 at 11:29