Skip to main content
Oct 14, 2021 4:49 AM UTC
Solved

UTC to CDT Timezone

Hi,

How to convert the UTC Date Time to CDT in thingworx ?

@paic @c_lowy @slangley 

Thanks,
Shashi

Nov 27, 2021 9:26 AM UTC

Hi,

After lot of manipulation in the TimeStamp with Thingworx and JS Functions was not able to get proper time zone, so used the Third Party API for this. Use the below Code:

var params = {
 proxyScheme: 'http' /* STRING */,
 headers: {"Accept-Encoding":"gzip, deflate, br","Accept":"*/*","Content-Type": "application/json"},
 ignoreSSLErrors: true,
	url: "http://worldtimeapi.org/api/timezone/America/Chicago" /* STRING */,
};

// result: JSON
var CDTdate = Resources["ContentLoaderFunctions"].GetJSON(params);
//date = CDTdate.datetime;
date = ((CDTdate.datetime).split("T")[0]);
time = ((CDTdate.datetime).split("T")[1]);
timestamp = ((time).split(".")[0]);
hours = timestamp.split(":")[0];
if(hours > 12 ){
 result = date + " " + timestamp + " PM CDT";
}
else{
 result = date + " " + timestamp + " AM CDT";
 }

 

Thanks,
Shashi

4 replies

Oct 14, 2021 11:38 AM UTC

If you have a 'fixed' offset, you can just apply the offset.

If you don't know the offset, you'll somehow have to determine the 'locale' and then apply the offset.

Since client side automatically converts to client side local time, you'll also have to keep that in mind when doing the offset.

I recommend a simple google search for javascript converting date time to another timezone

 

If it is a fixed offset though, there are the date time code snippets so you can do 'datetimeaddhours'

Oct 14, 2021 1:46 PM UTC

Hi @PaiChung ,

Thanks for Quick Response, but tried in all ways, nothing helped, therefore reached out for the community !!

Thanks,
Shashi

Oct 14, 2021 2:22 PM UTC

Can you perhaps describe in more detail the situation you are facing?

When and where do you receive/have the data stored that needs to be converted, as well as for what reason?

pshashipreethamAuthorAnswer
Nov 27, 2021 9:26 AM UTC

Hi,

After lot of manipulation in the TimeStamp with Thingworx and JS Functions was not able to get proper time zone, so used the Third Party API for this. Use the below Code:

var params = {
 proxyScheme: 'http' /* STRING */,
 headers: {"Accept-Encoding":"gzip, deflate, br","Accept":"*/*","Content-Type": "application/json"},
 ignoreSSLErrors: true,
	url: "http://worldtimeapi.org/api/timezone/America/Chicago" /* STRING */,
};

// result: JSON
var CDTdate = Resources["ContentLoaderFunctions"].GetJSON(params);
//date = CDTdate.datetime;
date = ((CDTdate.datetime).split("T")[0]);
time = ((CDTdate.datetime).split("T")[1]);
timestamp = ((time).split(".")[0]);
hours = timestamp.split(":")[0];
if(hours > 12 ){
 result = date + " " + timestamp + " PM CDT";
}
else{
 result = date + " " + timestamp + " AM CDT";
 }

 

Thanks,
Shashi