How to get only the time from GlideDateTime

miyu
Tera Guru

I want to get only the time from GlideDateTime, but it does not work.
In getTime(), I get not only the time but also the date 1970-01-01.
I want to do a comparison with the GlideTime time, but thanks to this it does not work.
Is there any way to solve this problem?

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

string manipulation

var gdt = new GlideDateTime();

var onlyTime = gdt.toString().split(' ')[1];

gs.info("Only time ->" + onlyTime);

Regards
Ankur

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

Arathi Jyothind
ServiceNow Employee
ServiceNow Employee

The GlideDateTime method getUserFormattedLocalTime() returns only time, but not as GlideTime object 

var gdt = new GlideDateTime();
gs.info(gdt.getDisplayValue());
gs.info(gdt.getUserFormattedLocalTime());

 Output:

29-05-2024 14:37:23
14:37:23