cancel
Showing results for 
Search instead for 
Did you mean: 

JSON to Collection Weid Dates Issue

AdamOllerenshaw
Level 3
​​Hi

So we have come across a strange issue with JSON to Collection action not formatting some date/times correctly - date format is I believe called epoch (example of our date string being... \/Date(1555372800000)\/)

Once we convert our string into a collection using the above, some dates are being formatted as  1 day in the past with a time of 23:00. The dates being correctly formatted have time of 00:00. Weirdly it seems to be based on Month - November to March show correct date with time 00:00, April to October are wrong showing date-1 and time 23:00.

Using the above example through an online checker (epochconverter.com) shows GMT date as 16 April 2019 00:00:00. This string runs through the JSON to collection and date that comes out is 15 April 2019 23:00:00

Note this is Version 6.4

Has anyone come across this? or have any ideas on where to start looking to address?
 
hope to hear back

Regards

------------------------------
Adam Ollerenshaw
Process Automation Modeller
Computershare
Europe/Bristol - UK
------------------------------
11 REPLIES 11

 

warrenfelsh
Level 2
The JSON specification does not specify a format for exchanging dates which is why there are so many different ways to do it. JSON does not know anything about dates. What .NET does is a non-standard hack/extension. The problem with JSON date and really JavaScript in general – is that there's no equivalent literal representation for dates. In JavaScript following Date constructor straight away converts the milliseconds since 1970 to Date as follows:

var jsonDate = new Date(1297246301973);

Then let's convert it to js format:

var date = new Date(parseInt(jsonDate.substr(6)));

The substr() function takes out the /Date( part, and the parseInt() function gets the integer and ignores the )/ at the end. The resulting number is passed into the Date constructor .

For ISO-8601 formatted JSON dates, just pass the string into the Date constructor:

var date = new Date(jsonDate);


------------------------------
warren felsh
------------------------------