Timezone Offset/daylighttime saving

Feddy
Kilo Sage

Hi All,

How do I get timezone offset and day light saving applicable?(true or false) for opened for user timezone.

We have requiremnt in which we need to populate this values in notification.

currently I could only get user time zone by doing dot walking in opened for field. 

 

Any input on this would be much appreciated 🙂

1 ACCEPTED SOLUTION

Try that:

var openedFor = gs.getUser().getUserByID('opened_for');

var tz = Packages.java.util.TimeZone.getTimeZone(openedFor.getTZ()); //set time zone based on user record

var time = new GlideDateTime(); //utc

time.setTZ(tz); //set time based on tz variable

var timeZoneOffSet = time.getTZOffset(); // calculate offset from utc

time.setNumericValue(time.getNumericValue() + timeZoneOffSet); 

gs.print('the time you're looking for: ' + time)

 

Regarding Daylight Saving Time it depends what value is set on sys_user table:

"In general, if a time zone is specified based on location (for example, America/Los Angeles), the system automatically adjusts for daylight saving time. If a time zone is specified based on the name of a time zone (for example, GMT), which is discouraged, it does not typically adjust for daylight saving time."

https://docs.servicenow.com/bundle/istanbul-platform-administration/page/administer/time/reference/r_TimeZones.html

View solution in original post

8 REPLIES 8

You probably need to use getLocalTime():

var gdt = new GlideDateTime();
gdt.getLocalTime();

Thanks for the reply 🙂

but it is for the logged user right i,e me here..
but how do i pass opened for(caller of an incident) timezone and get it confirmed that the daylight saving is applicable?

Try that:

var openedFor = gs.getUser().getUserByID('opened_for');

var tz = Packages.java.util.TimeZone.getTimeZone(openedFor.getTZ()); //set time zone based on user record

var time = new GlideDateTime(); //utc

time.setTZ(tz); //set time based on tz variable

var timeZoneOffSet = time.getTZOffset(); // calculate offset from utc

time.setNumericValue(time.getNumericValue() + timeZoneOffSet); 

gs.print('the time you're looking for: ' + time)

 

Regarding Daylight Saving Time it depends what value is set on sys_user table:

"In general, if a time zone is specified based on location (for example, America/Los Angeles), the system automatically adjusts for daylight saving time. If a time zone is specified based on the name of a time zone (for example, GMT), which is discouraged, it does not typically adjust for daylight saving time."

https://docs.servicenow.com/bundle/istanbul-platform-administration/page/administer/time/reference/r_TimeZones.html

Thank you so much for your reply:)

As we all know that the time zone conversions are managed by the platform automatically in servicenow,

I have created a mail script as suggested,

 

for Offset,

var gdt = new GlideDateTime();

template.print(gdt.getTZOffset()/3600000);//to convert it form milliseconds

 

for dst,

var gdt = new GlideDateTime();
template.print(gdt.isDST());