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
Method | Result |
---|---|
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
Parameter | Description |
---|---|
format | A string that represents the formatting instructions according to java.text.SimpleDateFormat . See also below. |
obj | 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 . |
locale | An 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
.
Symbol | Meaning | Presentation | Example |
---|---|---|---|
G | era designator | (Text) | AD |
y | year | (Number) | 1996 |
M | month in year | (Text / Number) | July / 07 |
d | day in month | (Number) | 10 |
h | hour in am/pm (1~12) | (Number) | 12 |
H | hour in day (0~23) | (Number) | 0 |
m | minute in hour | (Number) | 30 |
s | second in minute | (Number) | 55 |
S | millisecond | (Number) | 978 |
E | day in week | (Text) | Tuesday |
D | day in year | (Number) | 189 |
F | day of week in month | (Number) | 2 (2nd Wed in July) |
w | week in year | (Number) | 27 |
W | week in month | (Number) | 2 |
a | am/pm marker | (Text) | PM |
k | hour in day (1~24) | (Number) | 24 |
K | hour in am/pm (0~11) | (Number) | 0 |
z | time 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.