Want to convert GMT to EST/PST by passing timezone
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2021 04:49 AM
Want to convert GMT to EST/PST by passing timezone. Can you please help me how can we do that in service now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2021 03:00 AM
Hi Paremsh,
I have tried below
var tz = Packages.java.util.TimeZone.getTimeZone('America/New_York'); //specify the time zone here
var gdt = new GlideDateTime();
gdt.setTZ(tz);
var convertedTime = gdt.getDisplayValue();
gs.info("convertedTime" + convertedTime);
im getting output as
convertedTime 2021-02-08 05:54:11
BUt I want to get output as
convertedTime 2021-02-08 05:54:1 AM EST without any hard coding EST by passing America/New_York'. To get automatically as EST.
Can you please tell me how can i do it.
Thanks,
Uday
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2021 03:21 AM
can you try this
I have set the timezone in variable and then used it
var timezone = 'EST';
var time = new GlideDateTime();
gs.info('GMT time is->'+time);
var tz = Packages.java.util.TimeZone.getTimeZone(timezone);
time.setTZ(tz);
var timeZoneOffSet = time.getTZOffset();
time.setNumericValue(time.getNumericValue() + timeZoneOffSet);
gs.info('EST time is->'+time);
var hours = time.getDayOfMonthUTC();
if(hours < 13){
time = time + ' AM ' + timezone;
}
else{
time = time + ' PM ' + timezone;
}
gs.info(time);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2021 04:29 AM
I dont think it is possible. You are passing a timezone, how the system will understand it have to be converted it into EST? there is no relation b/w America/New_York and EST, both are same timezones.