How to convert GMT date to EST

jesusemelendezm
Mega Guru

When importing expirydate from LDAP to sys_user table - I am obtaining an incorrect date. If user expiry date in Active directory is 31/12/2014 the date being displayed on the user form on ServiceNow is 01/01/2015 I was told that It is being imported on GMT and I need to convert it to EST. Can I do it directly on the date field?


Capture.JPG

1 ACCEPTED SOLUTION

It will only affect that one particular variable and field.   Your script is not quite right though as you need to modify the timezone for your gDate variable.   You need to put:



//converting GMT to Canada/Eastern


var tz = Packages.java.util.TimeZone.getTimeZone("Canada/Eastern");


gDate.setTZ(tz);



...right after you initialize the variable and before you assign the date to it.     You should end up with:



var gDate = Packages.com.glide.glideobject.GlideDateTime();


//converting GMT to Canada/Eastern


var tz = Packages.java.util.TimeZone.getTimeZone("Canada/Eastern");


gDate.setTZ(tz);


gDate.setValue(msDate);


View solution in original post

17 REPLIES 17

Jim Coyne
Kilo Patron

Check out this wiki article section - Using Time Zones - ServiceNow Wiki



If that does not work, try setting the timezone of the GlideDateTime object before setting the date:



var tz = Packages.java.util.TimeZone.getTimeZone("Canada/Eastern");


var gdt = new GlideDateTime();


gdt.setTZ(tz);



That should do it, I believe.   I know that Packages calls are "illegal" now, but there does not seem to be a new GlideScriptable object to replace it.


Jim, thanks for the wiki link,I tried it out but It didn't work. What do you mean by setting the timezone of the glideDateTime? where is it?


Hi Jim,



Can you please help me here:


When i execute gs.log(gs.daysAgoEnd(2)); from back ground script, i see the result as 2017-12-04 23:59:59


But when i execute gs.log(gs.daysAgoEnd(2)); from schedule job, i see the result as 2017-12-05 06:59:59



In docs.service-now.com, it says GMT. My instance & Profile is in Canada Mountain time, How do i get end of day as 23:59:59 to run int in schedule job.


Chandan23
Tera Expert

Use source script in the transform map:


var tz = Packages.java.util.TimeZone.getTimeZone("America/Chicago");


var gdt = new GlideDateTime();


gdt.setTZ(tz);


target.date= gdt.getDisplayValue();