Skip to main content
7-Bedrock
August 19, 2022
Solved

Timezone Problem

  • August 19, 2022
  • 4 replies
  • 3118 views

   hi  ,i get  a different date after use function dateFormat(new Date(),"yyyy-MM-dd")  and new Date(); i guess it was a Timezone Problem,

 

would you please tell me how to change the timezone to GMT+08 in thingworx?

1660905320116.png

1660905399623.png

 

Best answer by Sathishkumar_C

try to edit and check

 

C:\Program Files (x86)\ThingWorxFoundation\tomcat\apache-tomcat-9.0.62\bin\tomcat_windows_service.bat

 

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

 

Note: I haven't tested. Please be cautious.

4 replies

7-Bedrock
August 19, 2022

and my thingworx version is 9.3.0

17-Peridot
August 19, 2022

try this..

let dateValue = new Date();
let calculatedDateValue = dateAddMinutes(dateValue, 480);
result = dateFormat(calculatedDateValue,"yyyy-MM-dd HH:mm:ss") ;

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

 

7-Bedrock
August 19, 2022

hello,thanks for your reply,  I noticed the option 2,but what the method i installed thingworx is using ThingWorxFoundationPostgres-9.3.0-x64.exe,

in this way ,how can i add -Duser.timezone=GMT+08  to  Java Options?

17-Peridot
August 19, 2022

try to edit and check

 

C:\Program Files (x86)\ThingWorxFoundation\tomcat\apache-tomcat-9.0.62\bin\tomcat_windows_service.bat

 

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

 

Note: I haven't tested. Please be cautious.

17-Peridot
August 23, 2022

Hello,

 

You could try this since you are running thingworx 9.3.0:

 

 

let params = {
        timezoneName: 'Asia/Hong_Kong' /* STRING */ 
};
let offset = Resources["TimezoneServices"].GetOffsetFromTimezone(params);
let offsethrs = offset / 100;

let DateTimeIn = new Date();
let datehrs = dateAddHours(DateTimeIn, offsethrs);

let isoFormat = dateFormatISO(datehrs);

 

This way you would get the timezone of Hong Kong, but if you lookup the tzdata list on wikipedia you can also find others.

Hope this helps.

 

Best regards.

17-Peridot
August 24, 2022

@chenzhuang111 ,

 

Can you tell us the use case for the new Date()?  On the server, TWx should be using UTC time.  In the mashups, it gets converted to the local time on that clients machine.  The dates that appear in the Composer services can be a bit confusing because of this.  If you're looking to do date calculations in back-end services, you should be able to assume that ThingWorx will be using the UTC date.  If you are creating dates to show on mashups, I would maybe suggest using the Expression functions where possible to create those as I find it less confusing (and you eliminate a back-end call to the server).

 

-Nick