Date Formatting in Apex

Here’s a quick cheat sheet on displaying dates and date info via Apex.  In this example I’ll use system date for “right now”…but you can do this with any instance of the Date class.

Day of the week:

system.now().date().format(‘EEEE’);

Month of the year:

system.now().date().format(‘MMMMM’);

Year-Month-Day:

string.valueof(system.now().date())

Month/Day/Year:

system.now().date().format()

 

***You can find additional examples here: Java SimpleDateFormat