How to get current date and time based on users timezones
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2015 09:19 AM
Hi All,
In our instance my time zone is US Eastern so when I am getting any date and time field value it is giving in US eastern. But my systems time zone is India so when I used "new Date()" it is giving value in India's timezone. So I am not able to compare those two field values.Please see the below code I have written.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var stDate=new Date(getDateFromFormat(g_form.getValue('RequestedStartDate'),g_user_date_time_format));
var now = new Date();
//alert(stDate);
//alert(now);
if(stDate < now)
{
alert('System open time should be greater than or equal to current date and time');
g_form.clearValue('RequestedStartDate');
//return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2015 08:00 AM
new Date() pics up the date time form browser and not from the server.
on server side if you use .getDisplayValue() on any field, that gives you date time in user's time zone and format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2017 06:25 AM
That comes into string format. Can we convert it into GlideDateTime object and still retain the user's time zone?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2018 12:24 AM
This might be what your asking for?
As per:
https://hi.service-now.com/kb_view.do?sysparm_article=KB0594664
-----------------------------------------------------------------------------------------
The setValue() and getValue() methods require parameters in the UTC time zone and internal format. Other formats may return invalid results.
The toString() method returns the same string as the getValue() method.
The setDisplayValue() and getDisplayValue() methods require parameters in the local time zone (user/system) and local format (user/system). Other formats may return invalid results.
//Example: If user’s date time format is MM.dd.yyyy HH:mm:ss
// Do this
var input = “08.05.2015 16:21:47”;
var gdt = new GlideDateTime();
gdt.setDisplayValue(input);
// Not this
var input = “08.05.2015 16:21:47”;
var gdt = new GlideDateTime(input);
-----------------------------------------------------------------------------------------
-Anders

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2021 01:43 AM
Your comment is really helpful for me.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2021 01:51 AM
Thanks for the feedback - glad to help.
-Anders