Issue in calculating time difference in different timezone
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2022 11:14 PM
Hi Team,
My system timezone is in EST and servicenow timezone is in IST. Below are the script which calculate time difference but its not working properly.
Catalog Client Script:-
BIIB_CPGResizeConfirmDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
chkCurrDate: function() {//Check if given Date time is in past or not.
var ActualEndDate = this.getParameter('sysparm_time');
var dif = gs.dateDiff(gs.nowDateTime(), ActualEndDate, true);
if (dif < 1800) {
return false;
} else {
return true;
}
},
chkstartstopDate: function() {//Check if given Date time is in past or not for start stop.
var ActualEndDate = this.getParameter('sysparm_time');
var dif = gs.dateDiff(gs.nowDateTime(), ActualEndDate, true);
if (dif < -2) {
return false;
} else {
return true;
}
},
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2022 04:06 AM
Hello Kun,
Please check with below code:
If you still get issue just once check replacing the below line
selectedTime.setNumericValue(selectedTime.getNumericValue() + (timeZoneOffSet));
with this one
selectedTime.setNumericValue(selectedTime.getNumericValue() + (timeZoneOffSet - 3600000));
var CustomClientDateTimeUtils = Class.create();
CustomClientDateTimeUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
compareToCurrentTime: function() {
var enteredTime = this.getParameter("sysparm_selected_time");
var selectedTime = new GlideDateTime(enteredTime); // Display date retrieved
var tz = Packages.java.util.TimeZone.getTimeZone("EST");
selectedTime.setTZ(tz); // Set timezone
var timeZoneOffSet = selectedTime.getTZOffset(); // Get offset of timezone set above
if (timeZoneOffSet < 0) {
timeZoneOffSet = timeZoneOffSet * -1;
}
selectedTime.setNumericValue(selectedTime.getNumericValue() + (timeZoneOffSet)); // Add offset to current time
var selectedTimeInGMT = new GlideDateTime(selectedTime.getValue()+ "");
var selectedTimeInUserTimeZone = selectedTimeInGMT.getDisplayValue();
var currentTimeInGMT = new GlideDateTime();
var currentTimeInUserTimeZone = currentTimeInGMT.getDisplayValue();
if (selectedTimeInUserTimeZone < currentTimeInUserTimeZone)
return false;
} else {
return true;
}
},
type: 'CustomClientDateTimeUtils'
});
Please mark my respsone as helpful/correct, if it answer your question.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2022 12:17 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2022 12:23 AM
Hello kun,
Please always make sure to share the lastest script that you have written in your instance. Just looking at the screenshot it is difficult to understand.
Thanks