- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2023 01:18 AM - edited 04-16-2023 03:09 AM
Hi Team,
I am trying to convert the given date in ISO format and its returning the data as well but date and time is in Europe/Amsterdam timezone and when you convert it to UTC/ISO, it should be less than two hours. So when time 13:05:57 is converted, it should return
Hi Team,
I am trying to convert the given date in ISO format and its returning the data as well but date and time is in Europe/Amsterdam timezone and when you convert it to UTC/ISO, it should be less than two hours. So when time
var gdt = new GlideDateTime('15-04-2023 13:05:57');
gs.print(gdt);
gs.print(gdt.getUserTimeZone());
var dt = gdt.getValue().split(' ');
var f = dt[0].split('-');
var t = dt[1].split(':');
var event = new Date(f[0], f[1]-1, f[2], t[0], t[1], t[2]);
var isoDate = event.toISOString();
gs.info(isoDate);
Output
*** Script: 2023-04-15 13:05:57
*** Script: sun.util.calendar.ZoneInfo[id="Europe/Amsterdam",offset=3600000,dstSavings=3600000,useDaylight=true,transitions=184,lastRule=java.util.SimpleTimeZone[id=Europe/Amsterdam,offset=3600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]]
*** Script: 2023-04-15T20:05:57.000Z
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2023 04:25 AM
Hi @SM16 ,
When we create a new Date objet from these values, the timezone information is lost, and it defaults to the timezone of the browser or server running the script.
To fix this, you should explicitly set the timezone of the Date object to the timezone of the input value
var gdt = new GlideDateTime('15-04-2023 13:05:57');
gs.print(gdt);
gs.print(gdt.getUserTimeZone());
var dt = gdt.getValue().split(' ');
var f = dt[0].split('-');
var t = dt[1].split(':');
var event = new Date(Date.UTC(f[0], f[1]-1, f[2], t[0], t[1], t[2])); // Set timezone to UTC
var isoDate = event.toISOString();
gs.info(isoDate);
Regards,
Shravan.
Please mark this as helpful and correct answer, if this helps you
Shravan
Please mark this as helpful and correct answer, if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2023 04:25 AM
Hi @SM16 ,
When we create a new Date objet from these values, the timezone information is lost, and it defaults to the timezone of the browser or server running the script.
To fix this, you should explicitly set the timezone of the Date object to the timezone of the input value
var gdt = new GlideDateTime('15-04-2023 13:05:57');
gs.print(gdt);
gs.print(gdt.getUserTimeZone());
var dt = gdt.getValue().split(' ');
var f = dt[0].split('-');
var t = dt[1].split(':');
var event = new Date(Date.UTC(f[0], f[1]-1, f[2], t[0], t[1], t[2])); // Set timezone to UTC
var isoDate = event.toISOString();
gs.info(isoDate);
Regards,
Shravan.
Please mark this as helpful and correct answer, if this helps you
Shravan
Please mark this as helpful and correct answer, if this helps you