How to get current date time in user logged in time zone - client scripts

dharani2607
Tera Contributor

Hello,

I am using   var nowTime = new Date().getTime(); to get the current date time, but this is not returning in logged is user timezone.

Can anyone please let me know how to get urrent date time in user logged in  time zone in client scripts

Thanks

11 REPLIES 11

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you cannot get that in client side; please use GlideAjax and use script include

this line will work in server side

var timeZone = gs.getUser().getRecord().getValue('time_zone');
gs.info(timeZone);

Output:

find_real_file.png

Regards
Ankur

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

@Ankur Bawiskar 

I need to get the current date time in user specified timezone which was selected in user profile.

 

Hi @dharani2607 try below in background script for a check.

var nowTimeis=new GlideDateTime().toString();
var timeis=nowTimeis.split(' ')[1];
gs.print(timeis);

Hi,

this would give you in server side

var gdt = new GlideDateTime();

gs.info(gdt.getDisplayValue());

Regards
Ankur

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