Need to Set Time for scheduled job based on time_zone in cmn_location table.

VikramM1
Tera Contributor

How to get time based on the display value of timezone field in cmn_location table.

 

I am running one schedule job periodically and set time zone based on IST with below code. But i want to set timezone based on Timezone field in cmn_location table. Can someone provide me the code to set time based on timezone available in timezone field.

 

var gdt = new GlideDateTime();
        var gdt1 = new GlideDateTime();
        var tz = Packages.java.util.TimeZone.getTimeZone("IST"); // sets to IST
        gdt1.setTZ(tz);
        gdt1.setValue(gdt);
        var time= gdt1.getDisplayValueInternal(); // Use getDisplayValueInternal() for 24-hour format
        time= new GlideDateTime(start);
1 ACCEPTED SOLUTION

Amit Verma
Kilo Patron
Kilo Patron
5 REPLIES 5

Mark Manders
Mega Patron

How are you running this? What is the relation with the location table to this scheduled job? What are your trying to accomplish? And did you try anything related to the answer you got on your question from last week?


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

I have one table form which will trigger messages based on selected time. I am comparing current IST time with user selected time and triggering messages based on time selected by user. Since, now i need to trigger messages by comparing user selected time and time comes from timezone in cmn_location table. Since, i want logic to get time based on timezone field and compare with user selected time and trigger messages. Timezone filed contains timezones like US/Pacific, IST, Hongkong etc.

Amit Verma
Kilo Patron
Kilo Patron

Hi @VikramM1

 

Below posts could be helpful :

https://www.servicenow.com/community/in-other-news/demystifying-glidedatetime-and-timezones-also-con....

https://www.servicenow.com/community/developer-forum/how-to-get-a-time-of-the-particular-time-zone-b...

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

How to get month, monthday and week based on time zone.