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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

date in label widget

AP_10343008
15-Moonstone

date in label widget

I want to show date in label widget. If i passed new Date(), it is diplaying 1725475328533. If i passed 

let date = new Date(); TimeString = date.toString(); then it is displaying 'Wed Sep 04 2024 14:15:55 GMT-0000 (UTC)'. This is not server time. I want to display server time in label widget or text field widget. How to do this ?
 
ACCEPTED SOLUTION

Accepted Solutions

I used new Date() inside a service. If the output passed to datetime picker widget, it displaying server time. Nut when the output passed to label widget, it displays UTC time. So I used datetime widget instead of label widget. 

View solution in original post

3 REPLIES 3

With every post, please include which TWX version you are running.

You did not specify if you run your code in an expression on in a service. Expressions are run in the browser, hence in browser local time. Services are run in server local time. Your server SHOULD run in UTC timezone, so the date would be correct, even if the server is physically in a different timezone.

 

Please see these articles for reference.

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

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

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

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

 

If you need a different timezone in your date, just add the difference between UTC and your desired timezone to the date.

 

DanZ
15-Moonstone
(To:AP_10343008)

Datetime objects created in services (i.e., on the server side) always use the service timezone (usually UTC). So if you want to display the user's current datetime, either let your service output the datetime object and do the formatting in an expression, or create the datetime directly in an expression. Thingworx converts datetime objects automatically to the users browser timezone.

I used new Date() inside a service. If the output passed to datetime picker widget, it displaying server time. Nut when the output passed to label widget, it displays UTC time. So I used datetime widget instead of label widget. 

Announcements


Top Tags