cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

How to convert date from JSON into Thingworx Date format

mfelton
1-Newbie

How to convert date from JSON into Thingworx Date format

from a JSON file that is being fed into my service the date is formatted like this: "\/Date(1490609194000)\/"

How would i go about converting this into a format that Thingworx recognises as a DateTime?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
jamesm1
5-Regular Member
(To:mfelton)

You just need the numeric value and then can return that as a DATETIME type. i.e.:

var dateStr = "\/Date(1490609194000)\/"

var date = dateStr.match(/[0-9]+/)[0]

result = date

you could also do:

var dateStr = "\/Date(1490609194000)\/"

var date = dateStr.match(/[0-9]+/)[0]

result = new Date(Number(date))

View solution in original post

1 REPLY 1
jamesm1
5-Regular Member
(To:mfelton)

You just need the numeric value and then can return that as a DATETIME type. i.e.:

var dateStr = "\/Date(1490609194000)\/"

var date = dateStr.match(/[0-9]+/)[0]

result = date

you could also do:

var dateStr = "\/Date(1490609194000)\/"

var date = dateStr.match(/[0-9]+/)[0]

result = new Date(Number(date))

Top Tags