Any Timezone to GMT timezone

SivaKumar123
Tera Contributor

The user would like the times that are entered in the Escalation  Date/Time and the Probably escalation Date/Time variables to automatically convert time to GMT when they are displayed in the task. The user needs to see those times in the task that is created in the GMT time zone.

 

Please help me, how to update the converted time into the task 

4 REPLIES 4

Bert_c1
Kilo Patron

Hi,

 

DateTime fields are stored in UTC. So any user who has their Time zone set to GMT should see the correct value for their time zone.

 

https://docs.servicenow.com/bundle/utah-platform-administration/page/administer/time/reference/r_Use...

 

Which states: "These values are stored as integer numbers, in milliseconds, and appear in the appropriate date or date/time format."

SivaKumar123
Tera Contributor

Hi Bert,

 

Thanks for the update.

the user wants to create a separate field and capture the time and offset to GMT in a separate field

If you create a Date Time field SN will show it based on the user's time zone only. So you can create 2 string fields , convert into and save the time in there.

 Escalation  Date/Time -> User enters data in their time zone

 Escalation  Date/Time (GMT) -> String field, You convert the value from previous field and save here. Also make this read only.

 

Same for the other field.

-Anurag

SivaKumar123
Tera Contributor

Hi,

the user wants to update the GMT time zone on the description of the task.

I have tried this script, but it's not working please help me with the changes

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {

return;
}

var start = g_form.getValue('escalation_date');
var end = g_form.getValue('probably_date');

g_form.setValue('MST_start_date', toMST(start));
g_form.setValue('MST_end_date', toMST(end));

}


function toMST(start){
var time = new GlideDateTime(start);
var tz = Packages.java.util.TimeZone.getTimeZone("GMT");
time.setTZ(tz);
var timeZoneOffSet = time.getTZOffset();
time.setNumericValue(time.getNumericValue() + timeZoneOffSet);
return time;
}