How to get separate date and time according to UTC format?

Akki1
Tera Contributor

I need date and time in two different variables according to UTC . Any help how can I achieve this?

8 REPLIES 8

Samaksh Wani
Giga Sage
Giga Sage

Hello @Akki1 

 

use string.split("T"); for spliting date and time into 2 different Variable.

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh

@Samaksh Wani 

If I do var gdt=new GlideDateTime();

gdt.getValue();

 

I'm not getting this "T" in between I get something like 2023-08-20 15:12:60 . How do we get "T" ?

Hello @Akki1 

 

Use the below to get date and time seperately

 

var dateArr =gdt.split(' ');

var time = dateArr[1];//Return time

var date = dateArr[0];//return date

If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact

Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.

@Akki1 

Try below code

var gdt=new GlideDateTime();

var gdtDate = gdt.getValue();

var date =gdtDate.split(' ');//split with space ,you will get date and time 

var date1 = date[0];//this will give you date

var time = date[1];//This will give you time 

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact

 

Thanks,

Manjusha