I am generating current date in the js controller class. And, in the helper class, When I call the Apex method I am sending the date to apex as parameters. Here's the code:
//controller.js
doInit : function(component, event, helper) {
var toDate = new Date();
component.set("v.mToDate", (toDate.getMonth()+1) + "/" + toDate.getDate() + "/" + toDate.getFullYear());
}
//helper.js
doInit : function(component, event, helper) {
var toDate = component.get("v.mToDate");
var dToDate = new Date(toDate);
console.log('TO: ' + dToDate);
var action = component.get("c.getCount");
action.setParams({
toDate : dToDate
});
$A.enqueueAction(action)
}
//class.apxc
@AuraEnabled
public static Integer getCount(Date toDate) {
System.debug('Date: ' + toDate);
}
When , I run the code: In the helper js class, this is the log I got:
TO: Wed Aug 19 2020 00:00:00 GMT+0530
But, in the apex class, this got printed:
Date: 2020-08-18 18:30:00
So, the problem is, in the apex class, a day is getting subtracted from the date. How can I prevent this? I want same dates in the helper and apex classes.
Also, I am from India. Here, current date is 19 Aug.