How do I get the local date/time when using GlideDateTime().getTime().getByFormat('hh:mm:ss a');

User151789
Mega Contributor

I need to get the custom formatted display value of a date/time field, but I would like to do it with one GlideDateTime object and not have to feed one to the other as shown below.   Let me know if you know of a better way.

This only seems to return the UTC value

var gdt = new GlideDateTime();

gs.info(gdt.getTime().getByFormat('hh:mm:ss a'));

 

This is the only way I have found to return the display value, is there a better way?

var gdt = new GlideDateTime();

var hack = new GlideDateTime(gdt.getDisplayValue());

gs.info(hack.getTime().getByFormat('hh:mm:ss a'));

1 ACCEPTED SOLUTION

Jon Barnes
Kilo Sage

I think this would work:


gs.info((new GlideDateTime()).getLocalTime().getByFormat('hh:mm:ss a'));


View solution in original post

4 REPLIES 4

Jon Barnes
Kilo Sage

I think this would work:


gs.info((new GlideDateTime()).getLocalTime().getByFormat('hh:mm:ss a'));


Thanks Jonathan, I completely forgot about the getLocal methods.  


Hi Jonathan,



I am trying of print the highlighted field (its getting updated by BR as per additional comments update) as per User Location. Although I get correct time on Field (EST) , however I still get System Timezone (PST) on the Notification.



Please advise!!!



find_real_file.png


find_real_file.png



find_real_file.png


This should work for you:



template.print("Additional Comments given at : "   + (new GlideDateTime(abc)).getDate().getByFormat('dd/MM/yyyy'));