JSON Date to a Xojo Date

I have a JSON Date in this form:

“/Date(1392768000000)/”

After parsing it in JSON I got it as

“\/Date(1424390400000)\/”

What is the best way to convert it to a normal Xojo Date?
[Without using the new JSON Framework]

What date format is this? Normally, you simply have to parse this to a date yourself. For instance, Mailtags uses an SQL date.

[quote]Private Function getMailTagsDate(theDate as String) As Date

'make a date from the mail tags string

if theDate = “” then Return nil

dim DueDate as new Date

if InStr(theDate, " ") > 0 and InStr(theDate, “:”) > 0 then

dim MailParts(-1) as String = Split(theDate, " " )
DueDate.SQLDateTime = MailParts(0) + " " + MailParts(1)

else
DueDate.SQLDate = theDate
end if

Return DueDate

End Function[/quote]

This might be a .NET serialized date.

[quote]Date object, represented in JSON as “\/Date(number of ticks)\/”. The number of ticks is a positive or negative long value that indicates the number of ticks (milliseconds) that have elapsed since midnight 01 January, 1970 UTC.
The maximum supported date value is MaxValue (12/31/9999 11:59:59 PM) and the minimum supported date value is MinValue (1/1/0001 12:00:00 AM).[/quote]

This is not part of JSON, this is a Microsoft “hack”. You need to parse the string and then convert the ticks into a Xojo date yourself.

I think you are right.

Sound much for a Microsoft “own” JSON version.

I found this:
http://www.hanselman.com/blog/OnTheNightmareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx

OK, with the new date framework, I get it…:

Using Xojo.Core Dim seconds As Double seconds = 1424390400000 / 1000 Dim d2 As New Date(seconds, TimeZone.Current) MsgBox ( d2.Year.ToText + " " + d2.Month.ToText + " " + d2.Day.ToText )

1 Like

With the old date framework, this would be my solution:

Dim seconds As Double seconds = (1424390400000 / 1000 ) + 2082844800 Dim d2 As New Date d2.TotalSeconds = seconds MsgBox ( d2.Year.ToText + " " + d2.Month.ToText + " " + d2.Day.ToText )

FYI, JSON recognizes the following types only:

  • Object
  • Array
  • String
  • Number
  • true
  • false
  • null

Anything else has to be encoded as an object or string. See:

http://www.json.org