This is tested and working in my environment.
Use the below -
#set($dateObject=$spTools.getClass().forName("java.util.Date").newInstance())
#set($formattedDate=$spTools.formatDate($dateObject,"MM/dd/yyyy HH:mm"))
Current Date:$dateObject
Formatted Date:$formattedDate
Output
Current Date:Wed Jan 24 01:35:56 PST 2024
Formatted Date:01/24/2024 01:35
The method I have used here is -
* @param date Date to format
* @param formatString Format String (i.e. MM/dd/yyyy HH:mm)
* @return Formatted date string or empty string if date is null.
* If the formatString is invalid, the formatted date will default
* the short style date and time expected by the current locale
*/
public String formatDate(Object date, String formatString);