function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VRKVRK 

TimeZone issues in lighitng

Hi Team,
i am getting issue in Time zone for below my requirement : could you pls help on this:
 if(!$A.util.isUndefinedOrNull(effectiveDate)){
                    effectiveDate.setMonth(11);
                    effectiveDate.setDate(31);
                }

 effectiveDate = new Date(effectiveDate);
                if(!$A.util.isUndefinedOrNull(effectiveDate)){
                effectiveDate.setFullYear(effectiveDate.getFullYear() + 1);
                effectiveDate.setDate(effectiveDate.getDate() - 1);
                }

When i try to execute code , i am getting some times Date as 
12/31/2020
or 
01/01/2021
But i need 12/31/2020.
I know its related to Time zone ....
Can you pls help anyone this .
Thanks
VRK
AnudeepAnudeep (Salesforce Developers) 
Hi VRK, 

Use formatDate method in your controller

Posting some examples here: 
var now = new Date();
var dateString = "2017-01-15";

// Returns date in the format "Jun 8, 2017"
console.log($A.localizationService.formatDate(now));

// Returns date in the format "Jan 15, 2017"
console.log($A.localizationService.formatDate(dateString));

// Returns date in the format "2017 01 15"
console.log($A.localizationService.formatDate(dateString, "yyyy MM dd"));

// Returns date in the format "June 08 2017, 01:45:49 PM"
console.log($A.localizationService.formatDate(now, "MMMM dd yyyy, hh:mm:ss a"));

// Returns date in the format "Jun 08 2017, 01:48:26 PM"
console.log($A.localizationService.formatDate(now, "MMM dd yyyy, hh:mm:ss a"));

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_cb_format_dates.htm

If you find this answer helpful, please mark this as Best Answer so that it can help others in the community. Thank You!

Anudeep