Notes
Returns the Date as a string using the locale of the context user
Here are some examples:
date myDate = date.newInstance(2001, 3, 21);
String dayString = myDate.format();
system.debug(dayString);
Output: 2022-01-17 00:00:00
Datetime myDT = DateTime.newInstance(2022, 5, 4, 19, 37, 55);
String myDate = myDT.format('yyyy-MM-dd h:mm a');
System.debug(myDate);
Output: 2022-05-04 7:37 PM
Datetime myDT = DateTime.newInstance(2022, 5, 4, 19, 37, 55);
String myDate = myDT.format('yyyy-MM-dd');
System.debug(myDate);
Output: 2022-05-04
Datetime myDT = DateTime.newInstance(2022, 5, 4, 19, 37, 55);
String myDate = myDT.format('EEEE');
System.debug(myDate);
Output: Wednesday
Datetime myDT = DateTime.newInstance(2022, 5, 4, 19, 37, 55);
String myDate = myDT.format('EEE');
System.debug(myDate);
Output: Wed
Video
Video does not exists.