I have a date field in a custom object that stores the following:
2016-01-01 00:00:00
That is what SF tells me the field value contains, when I output it using System.debug() in my Apex code.
Datetime d = priceList.Campaign_Effective_Date_Start__c;
System.debug ('Campaign_Effective_Date_Start__c - d = ' + d);
I need to get a formatted version of this date as:
01/01/2016
I've tried several ways to format the date, but I always end up getting:
12/31/2015
I've read some postings that state that I need to adjust the date to take into account my time zone offset. I'm not sure I understand why, since I'm OK with the date as it is stored in the SF database. I don't have a need to adjust it to take into account my current time zone, which is EDT (or 'America/New_York').
Is there a way I get the original date in formatted correctly, without having to manipulate it based on my current time zone?
EST
which is -6 right now (I think) so it is rolling your date back. You need to use theTimezone
class and calculate the offset. Or store the proper datetime. Or change your datetime to a date field (if you don't need the time element).