Convert date and time from any time zone to GMT ?

tkalpa005
Tera Expert

  I have one requirement  where user can select timezone and date/time for blackout , once  RITM is approved we are creating schedule and entry . But the issue here is  start  date and end date  store in value in GMT which is from current user's time zone. I wanted to convert date and time from any time zone to GMT , is there any way to achieve this ?

 

Example:

Start Date : 2020-02-24 17:00:00

Time Zone selected by user : US/Eastern

Logged in user time Zone: Asia/Kolkata

Value store in Data Base in RITM :2020-02-25 11:30:00 (As per user logged in users Time Zone,)

We want Start Date value in Database should be :2020-02-25 22:00:00 (As per user selected Time Zone)

Any way to convert any time zone to GMT  dynamically ?

5 REPLIES 5

https://community.servicenow.com/community?id=community_question&sys_id=a2f04ba5db98dbc01dcaf3231f96...

 

You will need to invoke the built in SN timezone function:

// Get date from service now

 

      var time = new GlideDateTime(current.u_start_date);

 

      // Display date retrieved

 

      gs.print('GMT Time: '+time);

 

      // Set timezone

 

      var tz = Packages.java.util.TimeZone.getTimeZone("America/New_York");

 

      time.setTZ(tz);

 

      // Get offset of timezone set above

 

      var timeZoneOffSet = time.getTZOffset();

 

      // Add offset to current time

 

      time.setNumericValue(time.getNumericValue() + timeZoneOffSet);

 

      // Print date/time in desired timezone

 

      gs.print('Eastern time: '+time);