You need to sign in to do that
Don't have an account?
Gopinath418
DateTime field is always showing 12am in time slot in lightning
In lightning component I would like to map the DATETIME (custom) field with current datetime + 2hrs. I am mapping through apex code. The problem is that date is correctly mapped but the time is always showing 12 am. How can map time as well in lightning components
I tried in my dev org it's working fine
this is the sample code
Demo.app
dateCmp .cmp
dateClassInt .apxc
Regards
Ashif
All Answers
fetchReqDate:function(component, event, helper){
var action = component.get("c.fetchRequestedDate");
action.setCallback(this,function(a){
var state = a.getState();
if(state === "SUCCESS"){
console.log($A.localizationService.formatDate(a.getReturnValue(), "yyyy-MM-dd\'T\'HH:mm:ss.SSS a"));
component.set("v.dateTimeattribute",$A.localizationService.formatDateTime(a.getReturnValue(), "yyyy-MM-dd\'T\'HH:mm:ss a"));
var result = component.get("v.dateTimeattribute");
component.set("v.newAcc.Requested_Date__c",result);
var result2 = component.get("v.newAcc.Requested_Date__c");
var rec = component.get("v.newAcc");
}
Apex Class Method
===============
@AuraEnabled
public static string fetchRequestedDate()
{
string s=null;
DateTime currentDate = DateTime.now();
s = currentDate.format('yyyy-MM-dd\'T\'HH:mm:ss.SSS a');
return s;
}
As you suggested i have tried to convert th Requested date into ISOstring but got an error "
Thanks
Gopinath
If we takes the current date from the component itself then i am not getting any error by using 'today.toISOString()' but if i am trying to get the current date from apex class then trying to convert it into ISOstring like component.get("dateTimeattribut").ISOString(); then i am getting error as " no function "component.get("dateTimeattribut").ISOString()".
I need to fetch the datetime from apex class and then i want disply it in Lightning component.
Thanks
I tried in my dev org it's working fine
this is the sample code
Demo.app
dateCmp .cmp
dateClassInt .apxc
Regards
Ashif