Skip to main content
1-Visitor
March 28, 2017
Solved

How to convert date from JSON into Thingworx Date format

  • March 28, 2017
  • 1 reply
  • 2259 views

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

Best answer by jamesm1

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))

1 reply

jamesm15-Regular MemberAnswer
5-Regular Member
March 28, 2017

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))