Convert date from CST to UTC

Gurushant2
Mega Contributor

Hi, Guys there,

I need help in the Conversion of dates from CST to UTC. Tried couple of ways, but seems unreliable.

Can anyone help me the way to get CST date into UTC format ?

 

Below is the example and solution looking for,

var cstDate = "2020-07-24 09:10:00"; //CST time 9:10 AM.

var gdt = new GlideDateTime(cstDate);

gs.debug(gdt); //it prints 2020-07-24 09:10:00.

---------------------------------------------

Imagine CST to UTC has 6 hrs difference (may vary, sometimes 5, sometimes 6).

Imagine UTC to IST has 5.30 hrs difference (may vary).

Seeking for a solution which will return,

  • '2020-07-24 15:10:00' if I am in UTC Timezone.
  • '2020-07-24 20:40:00' if I am in IST Timezone.

In simple based on my current timezone.

 

PN: I am trying to get the solution being in the Scoped app.

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

where is this required?

whenever you initialize new GlideDateTime() it would be GMT/UTC only

Regards
Ankur

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

Hi Ankur,

I need this in scoped app actually.. I have updated my question with an example with what I am looking for. Have a look and suggest me on how I can get the desired output

 

GlideDateTime() will give in UTC but if we pass CST value in it, it will be showing that time. 

@Gurushant 

Since you require for scoped app

1) Create Script Include in global scope and accessible from all application scoped

2) then call that function from your custom scope app script

Script to convert; refer solution shared here from me

Enhance it as per your requirement for CST etc

Convert the date time field from user time zone to eastern time zone in business rule.

Regards
Ankur

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

That was really great for Global scope. But as per the process we follow, I cannot create any script include (Any object) in Global scope.