Formatting dates in templates

Summary

Within the Template Velocity context there are a couple of different Date formatting methods that allow you to change the how the dates are shown within the Template.

Some example methods

Within the $dateFormatter context there are couple of different methods that will format the dates in different ways.

$dateFormatter.format

This method allows to define a custom pattern to use when formatting the date. For more info about defining a custom pattern see: SimpleDateFormat (Java Platform SE 8 )

$dateFormatter.format(value, pattern)

Value - the string date value that should be formatted.

Pattern - this is the pattern that should be used to format the value.

Example method:

$dateFormatter.format($aComment.updated.asText(),"yyyy,MMM,dd HH:mm a")

Example output:

2023,Nov,07 09:13 AM

 

$dateFormatter.formatDate

This method formats only the date part of the value and will display in the following pattern dd/MMM/yy.

Value - is the string date value that should be formatted.

Example method:

Example Output:

 

$dateFormatter.formatDateTime

This method formats the date and time part of the value and will display using the following pattern dd/MMM/yy hh:mm a

Value - the string date value that should be formatted

Example method:

Example Output:

 

$dateFormatter.formatDay

This method only formats the day of the week and the time.

Value - the string date value that should be formatted

Example method:

Example Output:

 

$dateFormatter.formatTime

This method only formats the time of the day using format hh:mm a

Value - the string date value that should be formatted.

Example Method:

Example Output: