Want to convert GMT to EST/PST by passing timezone

Uday Tej
Giga Contributor

Want to  convert GMT to  EST/PST   by  passing timezone. Can you please help  me how can we do that in service now.

12 REPLIES 12

Hi Ankur, thanks for the reply but can i  pass "America/newyork  and get the output as EST?

Hi,

I tried giving that timezone name. It didn't work you can simply use EST

EST -> means America (NewYork) only

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

you can try this 

var gdt = new GlideDateTime();
var gdt1 = new GlideDateTime();

var timezone = "EST";
var tz = Packages.java.util.TimeZone.getTimeZone(timezone );

gdt1.setTZ(tz);
gdt1.setValue(gdt); //in place of gdt, you can mention your date/time object variable
start = new GlideDateTime(gdt1.getDisplayValue()); //returns the date/time in EST in date/time object
var fdate = start.getDate().getByFormat('YYYY-MM-dd') + " " + start.getTime().getByFormat('hh:mm a')+" "+timezone ;


gs.print(fdate );

Hi Pramesh, thanks for the reply but can i  pass "America/newyork  and get the output as EST. 

yes you can 

 

var gdt = new GlideDateTime();
var gdt1 = new GlideDateTime();

var timezone = "EST";
var tz = Packages.java.util.TimeZone.getTimeZone('America/newyork' );

gdt1.setTZ(tz);
gdt1.setValue(gdt); //in place of gdt, you can mention your date/time object variable
start = new GlideDateTime(gdt1.getDisplayValue()); //returns the date/time in EST in date/time object
var fdate = start.getDate().getByFormat('YYYY-MM-dd') + " " + start.getTime().getByFormat('hh:mm a')+" "+timezone ;


gs.print(fdate );