I was refactoring some code and found this:
DateTime CurrentDateTime = System.now();
Datetime ESTDate = Datetime.newInstance(CurrentDateTime.year(),CurrentDateTime.month(),CurrentDateTime.day(),CurrentDateTime.hour(),CurrentDateTime.minute(),CurrentDateTime.second());
String myDateFormat = ESTDate.format('yyyy-MM-dd hh:mm:ss');
String myDate = myDateFormat.replace(' ', 'T');
object1.birthDate = myDate;
And I changed it to
object1.birthDate = datetime.now().format('yyyy-MM-dd\'T\'hh:mm:ss');
CurrentDateTime isn't used anywhere just in those four lines. How a programmer can even do that? Or WHY?
DateTime
is the standard 'timestamp' type, andSystem.Now
is the 'current timestamp' property. Personally, though, I'm a little suspicious of anything namedobject1
, and storing the time for a birthdate (while technically people are born at a particular 'instant', nobody ever thinks of them that ways - it tends to be the 'local calendar day'). That, and outputting it as a formatted string. It looks like there may have been an attempt to deal with timezones, but I don't see anything that actually references them, so... \$\endgroup\$