The CreatorCon Call for Content is officially open! Get started here.

I need to convert GMT date/time format into IST format.

niveditakumari
Mega Sage

Hello,

I am getting value of date/time field in GMT format from one API and inserting that value to my table. I need to convert that GMT format into IST then I want to insert that value in my table.

Can anyone please help me with this.

 

Regards,

Nivedita

1 ACCEPTED SOLUTION

Hi, It's bcoz your system timezone is ist. So while storing it is converting to ist. If you don't want that conversion then in our earlier code, Just change this line and uncomment the other lines. Packages.java.util.TimeZone.getTimeZone("IST"); //sets to IST TO Packages.java.util.TimeZone.getTimeZone("GMT"); //sets to GMT and check.

View solution in original post

42 REPLIES 42

Hi, It's bcoz your system timezone is ist. So while storing it is converting to ist. If you don't want that conversion then in our earlier code, Just change this line and uncomment the other lines. Packages.java.util.TimeZone.getTimeZone("IST"); //sets to IST TO Packages.java.util.TimeZone.getTimeZone("GMT"); //sets to GMT and check.

Just use earlier code of setting timezone. In place of ist, use GMT and it will work

I have updated my code like this : 


var gdt = new GlideDateTime();
var tz = Packages.java.util.TimeZone.getTimeZone("GMT"); //sets to IST
gdt.setTZ(tz);

for(var i = 0; i<obj.plannedEvents.length; i++) {

var gr = new GlideRecord('u_tcl_plannedevents');
gr.addQuery('u_ticket_id', obj.plannedEvents[i].ticketId);
gr.query();
if (!gr.next()) {
gs.log("insert records");
gr.initialize();

var Event_start_date = obj.plannedEvents[i].plannedEventStartDate;
var Event_end_date = obj.plannedEvents[i].plannedEventEndDate;
gs.log("Start and end dates are "+Event_start_date+"---"+Event_end_date);
gdt.setValue(new GlideDateTime(Event_start_date));
gdt.setValue(new GlideDateTime(Event_end_date));
gr.u_plannedevent_start_date = gdt.getDisplayValue();
gr.u_plannedevent_end_date = gdt.getDisplayValue();

 

Please correct me if i am wrong.

 

Regards,

Nivedita

Almost corect.

 

1 change is you put this line

gdt.setValue(new GlideDateTime(Event_end_date));

After

gr.u_plannedevent_start_date = gdt.getDisplayValue(); 

Alsoin logs, add a log after you assign to table field

gs.log(" converted date is "+ gdt.getDisplayValue());

 

and share the logs output.

Hi Nivedita, Would be great if you mark my other comments as helpful.