- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2017 04:38 AM
Hello,
I've been searching on the forums and elsewhere but haven't found a satisfactory answer for this.
I have a business rule that runs on a change when it reaches the implementation stage. I need to get the start and end time for the change and send it to another system via a rest request.
I can get the details but I want to make sure the time I send is the epoch time corresponding to the US/Central timezone.
The code as of now is as follows:
var start_date = current.start_date.dateNumericValue()/1000;
var end_date = current.end_date.dateNumericValue()/1000;
var ps_dt = new GlideDateTime();
gs.addInfoMessage(start_date);
gs.addInfoMessage(end_date);
gs.addInfoMessage(ps_dt); //The current time
var tz = Packages.java.util.TimeZone.getTimeZone("US/Central");
//Set the timezone
ps_dt.setTZ(tz);
var offset = ps_dt.getTZOffset()/1000;
start_time=start_date + offset;
end_time= end_date + offset;
I was assuming that the start_date and end_date values would be in GMT/UTC but that doesn't seem to be the case. Those values are in US/Central time. That may be because the user time that created the change is US/CT.
I want to make sure the time that I send is always in US/CT regardless of the time zone in the system.
Regards,
Karan.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2017 05:19 AM
Hi Karanpreet,
Date/time fields are always stored in UTC/GMT format and displayed based on user's timezone in ServiceNow
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2017 04:43 AM
Hi Karanpreet,
Great that it worked.
Could you also mark the answer as helpful and hit like. Thanks in advance.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader