How to get current month using apex in Salesforce?

How to get current month using apex in Salesforce?

Month() method can be used to get current month using apex in Salesforce. Also, format( ‘MMMM’ ) can be used to return the month in String since the Month() method returns integer.

Sample Code:

Integer intMonth = Date.Today().Month();
System.debug(
    'Current Month is ' + intMonth
);

To get the Month in String, use the following Code.

DateTime currentDT = System.now();
System.debug(
    'Current Month is ' + currentDT.format( 'MMMM' )
);

Leave a Reply