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

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

get time service return wrong time

AF_10333884
8-Gravel

get time service return wrong time

Hi,

 

I want to get my current time using this code:

var currentdate = new Date();
var datetime = "Last Sync: " + currentdate.getDate() + "/" + (currentdate.getMonth()+1) + "/" + currentdate.getFullYear() + " @ " + currentdate.getHours() + ":" + currentdate.getMinutes() + ":" + currentdate.getSeconds();
var result = datetime;

 

but the result I got is not correct, The date is suitable but the hour, minute and second are wrong.

 

ACCEPTED SOLUTION

Accepted Solutions
Velkumar
19-Tanzanite
(To:AF_10333884)

Hi @AF_10333884 

 

You can use the below snippet to convert DATETIME to STRING

 

var timeValue = new Date();
var result = "Last Sync :" + dateFormat(timeValue,"dd/MM/yyyy @ HH:mm:ss");

 

In the below image, the output time value will be different from the local PC time. It is due to different timezone in Thingworx server. So when you convert DATETIME to STRING, Thingworx will return a string in the server timezone. 

Velkumar_0-1693888893935.png

 

Please check the below article for more information - 

https://www.ptc.com/en/support/article/CS331340

https://www.ptc.com/en/support/article/CS362537

Solved: Timezone Problem - PTC Community

 

/VR

View solution in original post

1 REPLY 1
Velkumar
19-Tanzanite
(To:AF_10333884)

Hi @AF_10333884 

 

You can use the below snippet to convert DATETIME to STRING

 

var timeValue = new Date();
var result = "Last Sync :" + dateFormat(timeValue,"dd/MM/yyyy @ HH:mm:ss");

 

In the below image, the output time value will be different from the local PC time. It is due to different timezone in Thingworx server. So when you convert DATETIME to STRING, Thingworx will return a string in the server timezone. 

Velkumar_0-1693888893935.png

 

Please check the below article for more information - 

https://www.ptc.com/en/support/article/CS331340

https://www.ptc.com/en/support/article/CS362537

Solved: Timezone Problem - PTC Community

 

/VR

Announcements


Top Tags