- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2023 10:17 AM
I need to convert any time zone to the GMT time zone.
Variable names: Escalation date and Probably date'
Type: Date /Time
Need to update the time zone on the variable name: Start date, End date, and type : single text.
Please help me with the code.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var start = g_form.getValue('escalation_date');
var end = g_form.getValue('probably_date');
g_form.setValue('MST_start_date', toMST(start));
g_form.setValue('MST_end_date', toMST(end));
}
function toMST(start){
var time = new GlideDateTime(start);
var tz = Packages.java.util.TimeZone.getTimeZone("GMT");
time.setTZ(tz);
var timeZoneOffSet = time.getTZOffset();
time.setNumericValue(time.getNumericValue() + timeZoneOffSet);
return time;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2023 10:28 AM
GlideDateTime is not working in client side script, please try the Date object
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var start = g_form.getValue('escalation_date');
var end = g_form.getValue('probably_date');
g_form.setValue('MST_start_date', new Date(start).toUTCString());
g_form.setValue('MST_end_date', new Date(end).toUTCString());
}
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2023 10:28 AM
GlideDateTime is not working in client side script, please try the Date object
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var start = g_form.getValue('escalation_date');
var end = g_form.getValue('probably_date');
g_form.setValue('MST_start_date', new Date(start).toUTCString());
g_form.setValue('MST_end_date', new Date(end).toUTCString());
}
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2024 02:34 PM
Just to add for anyone else. I used the solution in an onSubmit client script and it worked for me too.