- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2017 06:44 PM
Hi folks,
I am trying to convert a server date/time format into a client date/time. There are two ways I can achieve this, one is to compensate the 10 hours difference (we are in AEST 10+ zone) to the date/time on server, GlideDateTime.addSeconds (60 seconds * 60 minutes * 10 hours)
The other I believe it can be achieved by GlideDateTime getLocalTime and getLocalDate functions, according to GlideDateTime Wiki, http://wiki.servicenow.com/index.php?title=GlideDateTime#getLocalDate.28.29 , the GlideDateTime.getLocalDate() and GlideDateTime.getLocalTime() can return the date/time in user's time zone.
However, not so sure if there is a direct function that can convert both date and time. For example,
var grIN = new GlideRecord('incident');
grIN.get('7a98b7dc4f580300052ea40f0310c762'); //query a particular IN record
gs.print(grIN.sys_created_on); // this returns *** Script: 2017-07-28 01:14:40 , which is server time
var d1 = new GlideDateTime(grIN.sys_created_on);
gs.print('Local Date: ' + d1.getLocalDate()); // this returns *** Script: Local Date: 2017-07-28
gs.print('Local Date Time: ' + d1.toString()); // this returns *** Script: Local Date Time: 2017-07-28 01:14:40
gs.print(d1.getLocalTime()); // this returns *** Script: 1970-01-01 11:14:40, which returns correct local time, but invalid date.
Is there a function that can convert both date and time?
Thank you in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2017 11:59 PM
Hi George,
The easiest way is just to return the display value which is in the user timezone:
var gr = new GlideRecord('incident');
gr.get('ef43c6d40a0a0b5700c77f9bf387afe3');
gs.print(gr.sys_created_on); //GMT
gs.print(gr.sys_created_on.getDisplayValue()); //PST
I get:
[0:00:00.004] Script completed in scope global: script
*** Script: 2017-03-07 18:05:40 //GMT
*** Script: 2017-03-07 10:05:40 //PST
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2017 11:59 PM
Hi George,
The easiest way is just to return the display value which is in the user timezone:
var gr = new GlideRecord('incident');
gr.get('ef43c6d40a0a0b5700c77f9bf387afe3');
gs.print(gr.sys_created_on); //GMT
gs.print(gr.sys_created_on.getDisplayValue()); //PST
I get:
[0:00:00.004] Script completed in scope global: script
*** Script: 2017-03-07 18:05:40 //GMT
*** Script: 2017-03-07 10:05:40 //PST
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2017 09:32 PM
Thanks Sergiu. didn't realize it would be that simple. Appreciate your advice.
Kind regards,
George