devC
devC

Reputation: 1444

Convert timestamp to normal date in JSON

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()));

Upvotes: 0

Views: 7164

Answers (1)

heikkim
heikkim

Reputation: 2975

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.

Upvotes: 1

Related Questions