Make sure time is in US/Central time in the business rule

karanpreet
Tera Guru

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.

1 ACCEPTED SOLUTION

Hi Karanpreet,



Date/time fields are always stored in UTC/GMT format and displayed based on user's timezone in ServiceNow



Regards


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Hi Karanpreet,



Great that it worked.


Could you also mark the answer as helpful and hit like. Thanks in advance.



Regards


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader