Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Display timezone code in mail script

russellprice
Tera Contributor

Hi

I have a field which is showing a time in a particular time zone using the code below:

var tz = Packages.java.util.TimeZone.getTimeZone("Asia/Manila");  
time.setTZ(tz);  
var timeZoneOffSet = time.getTZOffset();
time.setNumericValue(time.getNumericValue() + timeZoneOffSet);

I am using the content of this field in an email script which populates the email client to provide a time and date in that specific timezone.

This is working fine but there are a few formatting issues. Firstly it shows the time/date in this format:

2020-02-19 23:16:45

Is there a way I could change the formatting to show like this in the email:

dd/mm/yy hh:mm

Also, there are many timezones displayed in the email we send out, is there a way I can get the timezone code appended (GMT, CET etc) to the end of each? so that its clear what timezone each date/time are in? I would hard code it but this wont take into account Daylight Saving Time

Any assistence would be much appreciated.

7 REPLIES 7

Given that i have that article bookmarked i really should have thought to reference it 🙂

hmmm, the problem with that is that I am converting an existing field which shows the date and time the record was created, so the data is already in date/time format. Is it possible to split it up so I have the date then put it back together? I still cant find anything on displaying the timezone either.

Ok, ignore that, Ive worked out how to split out the existing date/time field and format it the way I need it but still cant work out how to display the timezone code. I tried

time.getByFormat("HH:mm zzz") 

But the timezone that was displayed was UTC, not the timezone i converted it to