I know that this topic was already created but the solutions given wasn’t suitable for me.
I want to change the date format for the email notifications like Access requests decision for self and others. IDN says we have to use the spTools to deal with date format however the spTools take a date as argument and the $removeDate is a string so we can’t use it. Consequently, I tried to parse the date from the string and it doesn’t work using the DateTool class even for a simple date “yyy mm dd”
It works for current date but how can you convert a input date in string format into a dateobject.
The purpose behind this process is to change its format.
@Sb_amir - Use the below to format an input date -
#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);
I have a date : String date = “01/01/2024”
To perform a format change we have to convert it into a Date type. However, i couldn’t instanciate a Date object from a string date (input) and the parse doesn’t seem to work either.
The code you gave me works to get and format the current date but it doesn’t answer my problem.