Convert UTC to EST using GlideRecord

divya321
Kilo Contributor

We have a requirement where I need to get the Scheduled start and end dates from email body which is in UTC format(both past and future dates will be available in email body)and convert this to EST. After converting it into EST we need to capture it on Planned start and end dates fields on change request.

I tried below code in my Inbound action

var startdt= email.body.scheduled_start;
var gdt = new GlideDateTime(startdt);
gdt.addSeconds(-14400);

var enddt= email.body.scheduled_end;
var gdt1 = new GlideDateTime(enddt);
gdt1.addSeconds(-14400);
//gs.log("date end _2 "+gdt1.getValue());

current.start_date = gdt.getValue();
current.end_date= gdt1.getValue();

Above code works fine for now but I have to change the seconds in code (gdt.addSeconds(-14400);) twice in an year because EST has daylight saving.

Could anyone help me what code needs be placed instead of updating the seconds manually in the code during day light saving.

 

Thanks,

Divya Saridey

 

 

1 ACCEPTED SOLUTION

Hello Try this

 

var startdt = new GlideDateTime(email.body.scheduled_start);
var tz = Packages.java.util.TimeZone.getTimeZone("America/New_York");
startdt.setTZ(tz);
var timeZoneOffSet = startdt.getTZOffset();
startdt.setNumericValue(startdt.getNumericValue() + timeZoneOffSet);

View solution in original post

5 REPLIES 5

glad i could help