Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
I have this function which takes lastVisitTime of type string.
string date value is "2024-11-12 10:00:01"
result of code when compiled on js compiler
let dateFromString = new Date("date in string");
output ->
2024-11-12T10:00:01.000Z
output type is
object
result of code when thingworx service is executed
let dateFromString = new Date("date in string");
output -> invalid date
output type is
object
could someone help me with this I want to convert my date string to date.
Thanks in advance.
Solved! Go to Solution.
When you give a string to new Date(), it must be in "YYYY-MM-DDTHH:mm:ss.sssZ" format.
Try replacing the space with a T:
2024-11-12 10:00:01 -> 2024-11-12T10:00:01 -> new Date("2024-11-12T10:00:01");
When you give a string to new Date(), it must be in "YYYY-MM-DDTHH:mm:ss.sssZ" format.
Try replacing the space with a T:
2024-11-12 10:00:01 -> 2024-11-12T10:00:01 -> new Date("2024-11-12T10:00:01");
Alternatively you can do this:
let date = parseDate("2024-11-12 10:00:01", "YYYY-MM-dd HH:mm:ss");