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 PTC Community Badges. Engage with PTC and see how many you can earn! X

UTC to CDT Timezone

pshashipreetham
17-Peridot

UTC to CDT Timezone

Hi,

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

@paic @c_lowy @slangley 

Thanks,
Shashi

Shashi Preetham
1 ACCEPTED SOLUTION

Accepted Solutions

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

Shashi Preetham

View solution in original post

4 REPLIES 4

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'

Hi @PaiChung ,

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

Thanks,
Shashi

Shashi Preetham

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?

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

Shashi Preetham
Top Tags