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

suvro
Mega Sage
Mega Sage

Check this out

 

https://community.servicenow.com/community?id=community_question&sys_id=38c40be9dbd8dbc01dcaf3231f9619e3

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi  dharani2607,

Ankur's reply is correct. "new GlideDateTime()" will get the date/time in UTC. .getDisplayValue() will return the date/time in current's user's date format and timezone.

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

getDisplayValue()

Gets the date and time value in the current user's display format and time zone.

https://developer.servicenow.com/dev.do#!/reference/api/sandiego/server_legacy/c_GlideDateTimeAPI#r_...

To get the date/time is yyyy-MM-dd HH:mm:ss format but in the current user's time format, use getDisplayValueInternal().

getDisplayValueInternal()

The date and time values for the GlideDateTime object in the current user's time zone and the internal date and time format of yyyy-MM-dd HH:mm:ss.