Easy Timezone Questions

G24
Kilo Sage

Hello great minds...

 

I understand that myGlideDateTime.getUserTimeZone() is the same thing as gs.getSession().getTimeZone()...

 

I have the following happy code:

 

 

gs.addInfoMessage("1) SERVER Timezone from JavaScript Date object: " + new Date().toLocaleString());

var myGR= new GlideRecord("sys_properties");
myGR.addQuery("name", "glide.sys.default.tz");
myGR.query();
while (myGR.next())
{
	gs.addInfoMessage("2) SYSTEM Timezone from System Property: " + myGR.value);
}
gs.addInfoMessage("3) USER Timezone from Session: " + gs.getSession().getTimeZone());

gs.addInfoMessage("4) USER Timezone offest from GlideDateTime: " + new GlideDateTime().getTZOffset() / 1000 / 60 / 60);

 

 

 

Which is producing the following happy output:

3.png

1)  This makes sense because our instance is hosted in California by ServiceNow.

2)  This makes sense because my company does business primarily in the Central timezone (Wisconsin).

3)  This makes sense, because I currently reside in Tampa, FL as I'm talking to you.

4)  This seems to be telling me that Eastern time is 4 hours behind GMT/UTC.  OK, great.

 

Here are my questions:

 

Question on Item 3)  How do I most effectively parse the results from gs.getSession().getTimeZone() so that I just have the part I care about which is "US/Eastern"?  The entire string looks like this:

 

sun.util.calendar.ZoneInfo[id="US/Eastern",offset=-18000000,dstSavings=3600000,useDaylight=true,transitions=235,lastRule=java.util.SimpleTimeZone[id=US/Eastern,offset=-18000000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]]

 

 

Question on Item 1)  What exactly is the string "PDT" here?  I mean, I know that it means Pacific Daylight Time, but where did the PDT abbreviation come from?  And how do I convert back and forth between Timezone IDs such as "US/Central" or "US/Eastern" and those magical abbreviations?  Thank you!!

1 ACCEPTED SOLUTION

Jaspal Singh
Mega Patron
Mega Patron

Hi Geoffrey,

 

Question 3: Why not use

gs.getUser().getTZ(); directly

 

Question 1: https://www.servicenow.com/community/developer-blog/convert-timezone/ba-p/2287262 has simpler method for conversion

View solution in original post

2 REPLIES 2

Jaspal Singh
Mega Patron
Mega Patron

Hi Geoffrey,

 

Question 3: Why not use

gs.getUser().getTZ(); directly

 

Question 1: https://www.servicenow.com/community/developer-blog/convert-timezone/ba-p/2287262 has simpler method for conversion

Thanks, @Jaspal Singh .  I didn't know about (or had forgotten about) gs.getUser().getTZ().

The documentation for GlideDateTime, under getUserTimeZone() mentions only gs.getSession().getTimeZone().  Not sure why they don't mention gs.GetUser().

 

I'm still curious how I would parse that weird getTimeZone string though.  But it's not a necessity.

Thanks again!