how convert current user time zone date/time into UTC

sree06
Tera Contributor

Hi all 
currently we are using soap outbound integration when were we are send date/time fields payload it should be convert into UTC time zone

Thanks in advance 
Sree

2 REPLIES 2

Amit Pandey
Kilo Sage

Hi @sree06 

 

Please check this-

 

 var userDateTime = new GlideDateTime();
    var userTimeZone = gs.getSession().getTimeZoneName(); 

    gs.info("User's Date/Time (Local): " + userDateTime.getDisplayValue()); 

    userDateTime.setTZ(userTimeZone);
    var utcDateTime = userDateTime.getDisplayValue(); // This will be in UTC

    gs.info("UTC Date/Time: " + utcDateTime);

 

Please mark my answer helpful and correct.

 

Regards,

Amit

James Chun
Kilo Patron

Hi @sree06,

 

Since ServiceNow stores date/time in UTC by default, there shouldn't be a need to convert it.

Use something like:

 

var someGDT = new GlideDateTime( current.getValue('date_time_field'));