How to get the timezone of the servicenow instance using REST API

Shahbaz Ali
Kilo Explorer

I need to get timezone and date format of the ServiceNow instance using REST API's, so going through the documentation I formulated a REST query as below :

https://xxxxx.service-now.com/api/now/v1/table/sys_user?sysparm_query=user_name=admin&sysparm_fields...

This query returns the timezone and date format but it returns empty value if the timezone is the System default. 

How can I get the system default timezone?

7 REPLIES 7

Naveen20
ServiceNow Employee
ServiceNow Employee

This should help. You just have to read the property from the sys_properties table as gs.getProperty('glide.sys.default.tz')

By default, the input field is blank. If no time zone is defined for this property, America/Los Angeles is used as the default.

 

find_real_file.png

Harsh Vardhan
Giga Patron

can you add more details on this requirement , why do you need api for this ? 

 

anyway as naveen mentioned about the properties so just want to add here if you did not define default time zone on your instance then gs.getProperty('glide.sys.default.tz')  will give you empty value. so you need to use below code to get the user time zone. 

 

var gdt = new GlideDateTime();
gs.print(gdt.getUserTimeZone());

Shahbaz Ali
Kilo Explorer

@Naveen you are saying the default timezone is America/Los Angeles if the property is blank. Is the default timezone same for all ServiceNow versions? can I assume if I am getting a blank timezone value then it must be 'America/Los Angeles'

Please help!

no it wont be for all the users. refer the script which i have added  that will give you the user  timezone