Velocity Date and Calendar Tools

Last Updated: Aug 26, 2022
documentation for the dotCMS Content Management System

In addition to customized tools for date and time handling, dotCMS has many built-in velocity tools that can be called directly in a widget, container, template, etc., for use on any dotCMS page.

Method Overview

MethodResult
getDate()Returns a Date object representing the time at which this method was invoked.
getCalendar()Returns a Calendar object representing the time at which this method was invoked.
getLocale()Returns an object representing the default locale.
getTimeZone()Returns the default Time Zone.
format()Returns a formatted string representing the specified date.
toDate()Returns a Date object representing the specified date.
toCalendar()Returns a Calendar object representing the specified date.

getDate()

Returns a Date object representing the time at which this method was invoked.

Date getDate()
Date getDate(Locale locale)

Takes either no parameter or an object of class java.util.Locale that represents the locale to be used to create the date.

Returns object of class java.util.Date representing the time at which this method was invoked in the specified locale. If no locale is specified, the system's default locale is used.

getCalendar()

Returns a Calendar object representing the time at which this method was invoked.

Calendar getCalendar()
Calendar getCalendar(Locale locale)

Takes either no parameter or an object of class java.util.Locale that represents the locale to be used to create the calendar.

Returns An object of class java.util.Calendar representing the time at which this method was invoked in the specified locale. If no locale is specified, the system's default locale is used.

getLocale()

Returns an object of java.util.Locale representing the default locale.

Locale getLocale()

Takes no parameter.

getTimeZone()

Returns an object of java.util.TimeZone representing the default time zone.

TimeZone getTimeZone()

Takes no parameter.

format()

Returns a formatted string representing the specified date.

String format(String format, Object obj)
String format(String format, Object obj, Locale locale)

Parameters

ParameterDescription
formatA string that represents the formatting instructions according to java.text.SimpleDateFormat. See also below.
objAn object of class java.util.Date or java.util.Calendar. It is also possible to pass a string that represents a parsable date according to java.text.DateFormat.
localeAn object of class java.util.Locale that represents the locale to format the date for.

Returns

Returns formatted date string in the specified locale or null if one or several input parameters are invalid. If no locale is specified, the system's default locale is used instead.

Date Formatting

This method uses the same formatting instructions as class java.text.SimpleDateFormat.

SymbolMeaningPresentationExample
Gera designator(Text)AD
yyear(Number)1996
Mmonth in year(Text / Number)July / 07
dday in month(Number)10
hhour in am/pm (1~12)(Number)12
Hhour in day (0~23)(Number)0
mminute in hour(Number)30
ssecond in minute(Number)55
Smillisecond(Number)978
Eday in week(Text)Tuesday
Dday in year(Number)189
Fday of week in month(Number)2 (2nd Wed in July)
wweek in year(Number)27
Wweek in month(Number)2
aam/pm marker(Text)PM
khour in day (1~24)(Number)24
Khour in am/pm (0~11)(Number)0
ztime zone(Text)Pacific Standard Time
'escape for text(Delimiter)
''single quote(Literal)'

toDate()

Returns a Date object representing the specified date.

Date toDate(Object obj)

Takes as parameter the date to convert. The parameter can be an object of class java.util.Date or java.util.Calendar. It is also possible to pass a string that represents a parsable date according to java.text.DateFormat.

Returns an object of class java.util.Date representing the converted date or of the input parameter is invalid.

toCalendar()

Returns a Calendar object representing the specified date.

Calendar toCalendar(Object obj)

Takes as parameter the date to convert. The parameter can be an object of class java.util.Date or java.util.Calendar. It is also possible to pass a string that represents a parsable date according to java.text.DateFormat.

Returns an object of class java.util.Calendar representing the converted date or of the input parameter is invalid.

On this page

×

We Dig Feedback

Selected excerpt:

×