I'm facing the issue in the Datetiem field type in the lightning component. I'm using for input and call apex method to save the fields for one of my events.

Requirement: Save the 2 DateTime field from lightning compoenent (Like on Event obejct) StartDateTime & EndDateTime.

Problem: Its take input correctly and save the date correctly but in time segments it always adds 5:00 AM:

My Component and code:

Lightning Component

<aura:component controller="DemoController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >

    <aura:attribute name="StartDatetime" type="String"  />
    <aura:attribute name="EndDatetime" type="String"   />
            <lightning:input type="datetime " name="input1" label="Start" required="true"   value="{!v.StartDatetime }"  />
            <lightning:input type="datetime " name="input2" label="End"   required="true"   value="{!v.EndDatetime }"  />            

            <lightning:button label="Save" variant="brand"  onclick="{!c.save}"/>




     save: function(component,event,helper){  

        var StartDatetime = component.get("v.StartDatetime");
        var EndDatetime = component.get("v.EndDatetime");

        //Call updateRec method from helper
        helper.updateRec(component,event, StartDatetime , EndDatetime );  


    updateRec: function (component,event, StartDatetime , EndDatetime ){

        var action = component.get("c.updateRecord");

            "StartDatetime": StartDatetime,
            "EndDatetime": EndDatetime,
        action.setCallback(this, function(response){
            var state = response.getState();

            // Display toast message to indicate load status
            var toastEvent = $A.get("e.force:showToast");
            if(action.getState() ==='SUCCESS'){
                    "type" : "success",                    
                    "message": " was saved."

                    "type" : "error",
                    "title": "There was a problem updating this",
                    "message": "some thing went wrong




public with sharing class DemoController {

    public static void updateRecord(string StartDatetime,string EndDatetime) {
        // this is hard code id of one of my event
       id recId='00U1G000006koFBUAY';     

    Event evnt = [SELECT Id,StartDateTime,EndDateTime  FROM Event WHERE Id = :recId];                
                  evnt.StartDateTime = date.valueof(StartDatetime);    
         evnt.EndDateTime = date.valueof(EndDatetime);      
                  update evnt;

1 Answer 1


i dont think we have any lightning:input with type attribute as "StartDatetime " we have "datetime" which can be use to set the timezone.

 <lightning:input type="datetime " name="input1" label="Start" required="true"   value="{!v.StartDatetime }"  timezone ="GMT"/>
  • you are right I'm using DateTime type
    – Faisal
    Feb 18, 2020 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.