Skip to main content
16-Pearl
September 4, 2024
Solved

date in label widget

  • September 4, 2024
  • 3 replies
  • 1129 views

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 ?
 
Best answer by AP_10343008

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. 

3 replies

Rocko
19-Tanzanite
September 5, 2024

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.

 

15-Moonstone
September 5, 2024

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.

AP_1034300816-PearlAuthorAnswer
16-Pearl
September 17, 2024

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.