We have a simple intake form with the following attributes. So you can think of the object records would be as follows:
|ID||Military Time||Time Zone||Add Days (from today's date)|
As you probably already know, a lot of the Date and DateTime methods in salesforce work's off of the User Context's Locale Time Zone or GMT.
Now we have user's around the country with different locale settings.
For example, when a user who's locale is in (GMT-04:00) Eastern Daylight Time (America/New_York) is executing the method, we would want the return to be specific to the record's time zone.
User's Local - (GMT-04:00) Eastern Daylight Time (America/New_York)
Today's Date is 3/24/2022
|1||3/27/2022 7:00 AM CDT|
|2||3/28/2022 6:00 AM CDT|
|3||3/25/2022 6:00 AM EDT|
I tried different approaches like for example the Record ID 1
String militaryTime= '0700'; Time timeValue= Time.newInstance(Integer.valueOf(militaryTime.substring(0, 2)), Integer.valueOf(militaryTime.substring(2, 4)), 0, 0); DateTime dateTimeVal = DateTime.newInstance(Date.Today().addDays(3), timeValue); System.Debug(dateTimeVal); //Returns 2022-03-27 11:00:00 System.Debug(dateTimeVal.format('MM/dd/yyyy HH:ss a z')); //Returns 03/27/2022 07:00 AM EDT System.Debug(dateTimeVal.format('MM/dd/yyyy HH:ss a z','America/Chicago')); //Returns 03/27/2022 06:00 AM CDT
Somehow it is not returning 3/27/2022 7:00 AM CDT, is there anything I am doing wrong here?