How can we convert IST time to PST

sam1212
Mega Expert

Hi All,

I was trying to convert IST time to PST ,any function available ?

Ex:

Input Time   2016-06-29 11:00:00 (IST)

OutPut : 2016-06-28 22:30:00 (PST)

I tried glide time object but they give GMT and then i have to manually add some additional minutes to get required result..

I was looking for a function like

ChangeTIme(Input time)

{

Code//

Return RequiredTime;

}

Any help will be appreciated..

3 REPLIES 3

Chuck Tomasi
Tera Patron

Hi Sam,



Go to https://developer.servicenow.com and search for GlideDateTime. There's a method called setTZ().



It takes a Timzone object, which can be retrieved with with getUserTimeZone(). I don't know what happens if you feed it something like



America/Los_Angeles



You could try.


rajeevhanda
Kilo Expert

Hi Sam,

There is a global script include: rmconverttimezone. Use this to convert from any time zone to other:

gs.print(rmConvertTimeZone('2019-02-27 11:44:52','UTC','US/Pacific'));

 

If you will use packages.java.util.timeZone......it's not considered best practice to use Java packages directly in ServiceNow code. Though the above function also uses the same, since that's out of the box so you will be saved. 

Thanks

Rajiv Handa

bhaskar8906
Giga Contributor

Rmconverttimezone is a global script inclusion. Use this to convert between any two time zones:


gs.print ("2019-02-27 11:44:52", "UTC", "US/Pacific");");

 

Using Java packages directly in ServiceNow code is not regarded as best practice, even if you use packages.java.util.timeZone. Although the aforementioned feature likewise makes use of the same, you will be spared because it comes pre-installed.