1

I want to encode the date format to send the date through my REST API request. I have sample response as createDate=1449092965474 I don't know which format it is. Kindly help me decoding this date format.

SavantMohan
  • 35
  • 2
  • 9

4 Answers4

3

It's a javascript date in milliseconds since 1970. (Reference: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date)

In this case:

new Date(1449092965474)

is

Wed Dec 02 2015 22:49:25 GMT+0100

I would recommend using ISO 8601 Format in your REST API.

Daniel Bauer
  • 168
  • 2
  • 12
  • how can i convert the YYYY-DD-MM to the milliseconds format? because API wants this date format. – SavantMohan Jan 13 '16 at 14:51
  • You can use [this method](http://stackoverflow.com/a/3067896/2391070). I personally use [momentjs](http://momentjs.com/) because of its great api. – Daniel Bauer Jan 13 '16 at 15:05
0

Dates written as numbers, specifies the number of milliseconds since January 1, 1970, 00:00:00. So if you convert it to normal date it will be Wed Dec 02 2015 16:49:25 GMT-0500 (Eastern Standard Time).

Foxy
  • 416
  • 8
  • 18
0

Server Side (C#)

Before Sending the date from your API.

Convert the date to a string.

like this .

string YourNewDateObj = YourDateObj.toString("yyyy-MM-dd HH:mm:ss");

Client Side

new Date(1449092965474)

This is give you response.

Kaushik
  • 2,072
  • 1
  • 23
  • 31
0

try this

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
Merrin K
  • 1,602
  • 1
  • 16
  • 27
K Kumar
  • 131
  • 5
  • 14
  • The community encourages adding explanations alongisde code, rather than purely code-based answers (see [here](https://meta.stackoverflow.com/questions/300837/what-comment-should-i-add-to-code-only-answers)). – costaparas Feb 17 '21 at 10:05