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

I already gave you reply earlier to another comment. Try like this. This will set the api date/time exactly in database. var Event_start_date = obj.plannedEvents[i].plannedEventStartDate; var Event_end_date = obj.plannedEvents[i].plannedEventEndDate; gr.u_plannedevent_start_date = Event_start_date; gr.u_plannedevent_end_date = Event_end_date; Mark the comment as a correct answer and helpful once worked.

I have done in same way but date/time is not same. I am getting time as 12:00 AM only.

Below is my screenshot : 

find_real_file.png

 

Below is my code : 

// update the record
gs.log("update records");
//var gdt = new GlideDateTime();
//var tz = Packages.java.util.TimeZone.getTimeZone("IST"); //sets to IST
//gdt.setTZ(tz);


var Event_start_date_1 = obj.plannedEvents[i].plannedEventStartDate;
var Event_end_date_1 = obj.plannedEvents[i].plannedEventEndDate;
gs.log("Start and end dates are "+Event_start_date_1+"---"+Event_end_date_1);
gr.u_plannedevent_start_date = Event_start_date_1;
gr.u_plannedevent_end_date = Event_end_date_1;

gr.u_rollback_plan = obj.plannedEvents[i].rollbackPlan;
//gr.u_plannedevent_start_date = obj.plannedEvents[i].plannedEventStartDate;
gr.u_closure_code = obj.plannedEvents[i].closureCode;
gr.u_description = obj.plannedEvents[i].description;
//gr.u_plannedevent_end_date = obj.plannedEvents[i].plannedEventEndDate;
gr.u_ticket_id = obj.plannedEvents[i].ticketId;
gr.u_correlation_id = obj.plannedEvents[i].correlationId;
gr.u_impact = obj.plannedEvents[i].impact;
gr.u_execution_owner = obj.plannedEvents[i].executionOwner;
gr.u_maintenance_type = obj.plannedEvents[i].maintenanceType;
gr.u_site_location= obj.plannedEvents[i].siteLocation;
gr.u_expected_downtime= obj.plannedEvents[i].expectedDowntime;
gr.u_activity_status= obj.plannedEvents[i].activityStatus;

 

Please correct me if i am wrong.

 

Regards,

Nivedita

 

It looks like your date is converting to ist format. Can you add this log and tell me what is your system timezone. var tz = gs.getSession().getTimeZone(); gs.log (" system time zone is "+tz); Also, tell me what is the timezone in which your dates are coming from api?

Below is my system time zone : 

find_real_file.png

I am getting below log after running this code : 

find_real_file.png

 

Timezone is in GMT format that is coming from api.

Hello,

Can you please help me why i am not getting the correct date/time similar to date/time which i am getting from API.

 

Regards,

Nivedita