Long or Date in JSON

0

Applications, one server and multiple clients, POST and GET to the server exchange JSON objects.

One of the variables that goes along with JSON is datahora atual , I see different Strngs to represent dates, such as:

"\"\/Date(1335205592410)\/\""         .NET JavaScriptSerializer
"\"\/Date(1335205592410-0500)\/\""    .NET DataContractJsonSerializer
"2012-04-23T18:25:43.511Z"              JavaScript built-in JSON object
"2012-04-21T18:25:43-05:00"             ISO 8601

Or even the error returned from the server, brings some examples of parsers to these dates:

(error: Failed to parse Date value 'Jun 7, 2017 08:44:51 AM': Can not parse date "Jun 7, 2017 11:44:51 AM": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"))

I searched, and there is little talk about representing that date in a long, sending and just creating a Date on the server or even saving as long in the database, so at least it seems simpler and would avoid these problems reading the date.

I know it's possible to do this, but I was curious about the few implementations, or almost none I found. So, using long , would it be wrong, or would it be some kind of "bad practice"?

    
asked by anonymous 07.06.2017 / 18:03

1 answer

0

Some databases have the type Datetime With TimeZone, and with this it does the management of TimeZone, if you save in milliseconds it will not be possible for example to know the time zone and whether it is daylight saving time or not example. If this does not make a difference for you to save in long, but it is recommended to use Date, and to solve this problem you should do a convert before sending to the server.

    
07.06.2017 / 22:25