Joda Time Plugin

The Joda Time plugin provides a Velocity-friendly API on top of the Joda Time library. The plugin is enabled by default in XWiki Enterprise, so you will find it in the "xwiki.plugins" list of the xwiki.cfg file:

#-# List of active plugins.
xwiki.plugins=\
...
  com.xpn.xwiki.plugin.jodatime.JodaTimePlugin,\
...

The source code is available on GitHub at xwiki-platform-jodatime.

Examples


{{velocity}}

## Format the displayed result
#set($formatter = $xwiki.jodatime.getDateTimeFormatterForStyle('F-'))

## Display the current time
#set($currentTime = $xwiki.jodatime.dateTime)
$formatter.print($currentTime)

## Display the second day of the current week
#set($secondDayWeek = $currentTime.withDayOfWeek(2))
$formatter.print($secondDayWeek)

{{/velocity}}

will display

JodaTimePlugin.png

Example using "getDateTimeFormatterForPattern"

{{velocity}}

#set($formatter = $xwiki.jodatime.getDateTimeFormatterForPattern("dd/MM/yyyy 'at' hh:mm"))

## Display the document creation time
#set($creationDate = $xwiki.jodatime.getDateTime($doc.creationDate.time))
Document created on $formatter.print($creationDate)

## Display the number of days left until Easter
#set($formatter = $xwiki.jodatime.getDateTimeFormatterForPattern('yyyy.MM.dd'))
#set($easterDay = $formatter.parseDateTime('2014.04.20'))
#set($now = $xwiki.jodatime.dateTime)
#set($daysLeft = $easterDay.minus($now.millis))
$daysLeft.getDayOfYear() days left until Easter

{{/velocity}}

will display 

JodaTimePluginPattern.png

More examples for the Joda Time plugin are available on xwiki.org.

Related Pages

Search this space