mamann
Mega Guru

I wanted to share something that I figured out recently, in the hopes that it will help others.
As everyone knows, dealing with DateTime values are very difficult and a common challenge that comes up is being able to convert a DateTime from one TimeZone to another.
I've read many articles on how to accomplish this and almost all of them involve using a Package Call, or won't work in a scoped app or involve lengthy code.


Well, I'm here to tell you, this can be accomplished with a few lines of code and works in a scoped app.

The class, GlideScheduleDateTime has a method called convertTimeZone which takes two arguments.
The first is the TimeZone you want to convert from and the second is the TimeZone you want to convert to.

 Listed below is example code which can be adjusted based on your use case.

var tzConvert = new GlideScheduleDateTime("2021-12-24 08:00:00");
tzConvert.convertTimeZone("US/Central", "Etc/UTC");
gs.info(tzConvert);

DISCLAIMER: This method is used in a few places OOB, but is undocumented, so use at your own risk, as it might change or become deprecated in the future.

Comments
Monika13
Giga Expert

Hi @mamann 

Could you please help me understand how to find values which you have mentioned in line number two?

where can we find exact name of time zone e.g "US/Central", "Etc/UTC" ?

Regards,

Monika

Version history
Last update:
‎02-10-2022 10:50 AM
Updated by: