cancel
Showing results for 
Search instead for 
Did you mean: 
Security Alert Log4j Security Vulnerability. Click here to know more.
cancel
Showing results for 
Search instead for 
Did you mean: 

Date in UTC

psp316r
14-Alexandrite

Date in UTC

Hi,

When result =  new Date() is executed, the result Time format is in IST, but as per the customer point of view it should be in UTC, how can it be done ?

Note: the output of the service should be DATETIME


@paic @slangley @c_lowy 

Thanks,
Shashi

1 ACCEPTED SOLUTION

Accepted Solutions
psp316r
14-Alexandrite
(To:psp316r)

Hi,

Since no solution is avaliable for this, using third party API's for Time is the easiest way.
In the Below Code used the CDT timezone, similarly it can be changed to the UTC.

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.

View solution in original post

3 REPLIES 3
PaiChung
21-Topaz II
(To:psp316r)

Google search shows there should be a Date.UTC available in javascript

See Article here

psp316r
14-Alexandrite
(To:PaiChung)

Hi @PaiChung ,

Sorry that didn't help ... !

Thanks,
Shashi

psp316r
14-Alexandrite
(To:psp316r)

Hi,

Since no solution is avaliable for this, using third party API's for Time is the easiest way.
In the Below Code used the CDT timezone, similarly it can be changed to the UTC.

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.

Announcements