Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X
I want to show date in label widget. If i passed new Date(), it is diplaying 1725475328533. If i passed
Solved! Go to Solution.
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.
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.
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.