Current time in user's timezone

snowtech1
Tera Expert

Can anyone help me with the script to get the time in the user's timezone?

var gt = new GlideDateTime();

var gdt = gr.getTime();

gs.print(gdt.getDisplayValue());

The script above is displaying with an error of (-1) hour.

Thanks in advance.

1 ACCEPTED SOLUTION

Use below if you just need time



var gt = new GlideDateTime();


gs.print(gt.getDisplayValue().split(' ')[1]);



Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

12 REPLIES 12

SanjivMeher
Kilo Patron
Kilo Patron

Use getLocalDate();


var gdt = new GlideDateTime("2011-08-31 08:00:00");


gs.print(gdt.getLocalDate());




http://wiki.servicenow.com/index.php?title=GlideDateTime#getLocalDate.28.29



Please mark this response as correct or helpful if it assisted you with your question.

Thank you for the reply.



But I need the time?


var gdt = new GlideDateTime("2011-08-31 08:00:00");


gs.print(gdt.getLocalTime());


It shows some junk value I believe.



var gdt = new GlideDateTime(gs.nowDateTime());


gs.print(gdt.getLocalTime());


1970-01-01 01:01:54



var gdt = new GlideDateTime("2011-08-31 08:00:00");


gs.print(gdt.getLocalTime());


1970-01-01 03:00:00