You need to sign in to do that
Don't have an account?
Irina Aristova
Format date function returns a wrong date
Irina AristovaFormat date function returns a wrong dateI converted Date time to string in Apex using format function:
DateTime yesterdayDate = Date.today().addDays(-1);
System.Debug(yesterdayDate);
String formattedDate = yesterdayDate.format('MM/dd/yyyy');
System.debug(formattedDate);
The result is:
USER_DEBUG|[24]|DEBUG|2015-05-05 00:00:00
USER_DEBUG|[27]|DEBUG|05/04/2015
I expected to be the same date: 05/05/2015, but it returned 05/04/2015 which is one day earlier
I need to convert date to a string but I am not able because it's returning the wrong date
The user object for me it's set up to:
Time Zone is (GMT-04:00) Eastern Daylight Time (America/New_York)
Locale: Enflish(United States)
Default Time Zone for company is the same as mine: (GMT-04:00) Eastern Daylight Time (America/New_York)
DateTime yesterdayDate = Date.today().addDays(-1);
System.Debug(yesterdayDate);
String formattedDate = yesterdayDate.format('MM/dd/yyyy');
System.debug(formattedDate);
The result is:
USER_DEBUG|[24]|DEBUG|2015-05-05 00:00:00
USER_DEBUG|[27]|DEBUG|05/04/2015
I expected to be the same date: 05/05/2015, but it returned 05/04/2015 which is one day earlier
I need to convert date to a string but I am not able because it's returning the wrong date
The user object for me it's set up to:
Time Zone is (GMT-04:00) Eastern Daylight Time (America/New_York)
Locale: Enflish(United States)
Default Time Zone for company is the same as mine: (GMT-04:00) Eastern Daylight Time (America/New_York)
Please try below with DateTime.Now() .
Let us know if it helps you.
All Answers
Please try below with DateTime.Now() .
Let us know if it helps you.
It solved the problem!