logo

MMBase tips

<mm:time time="today" /> prints today's date

tip #1 / Fri 19 Jan 2007 / André / 1 comments

The tag in the taglib has some great features. You can for example print today's date like "Thursday 8 February 2007" with a simple statement  <mm:time time="today" format="EEEE dd MMMM yyyy" />.

In your terminal change ('cd') to a directory that contains 'mmbase.jar', normally you will have one your local mmbase installations 'WEB-INF/lib' directory. Then insert this on the command line:

java -cp mmbase.jar org.mmbase.util.DynamicDate

You can also pass a classpath for mmbase. But this is the easiest way. The command will print the following which basically is an example of allmost all the ways to use the tag:

AD 1970-01-01 01:00:00.000 CET do 0
AD 1970-01-01 03:46:40.000 CET do 10000
AD 1969-12-31 22:13:20.000 CET wo -10000
AD 1970-01-01 01:16:40.000 CET do +1000
AD 1973-05-03 00:00:00.000 CET do 1973-05-03
AD 2006-05-09 00:00:00.000 CEST di 2006-05-09
BC 0004-12-25 00:00:00.000 CET di -3-12-25
AD 2000-01-01 16:00:00.000 CET za 2000-01-01 16:00
AD 2001-01-01 17:00:00.000 CET ma TZUTC 2001-01-01 16:00
AD 2007-01-24 12:34:56.789 CET wo today 12:34:56.789
AD 2007-01-24 11:16:21.998 CET wo now
AD 2007-01-24 00:00:00.000 CET wo today
AD 2007-01-25 00:00:00.000 CET do tomorrow
AD 2007-01-24 11:26:22.011 CET wo now + 10 minute
AD 2007-01-29 00:00:00.000 CET ma today + 5 day
AD 2007-01-01 00:00:00.000 CET ma now this year
AD 2007-08-01 00:00:00.000 CEST wo next august
AD 2007-08-01 00:00:00.000 CEST wo today + 6 month next august
AD 2007-01-01 00:00:00.000 CET ma tomonth
AD 2007-01-26 17:00:00.000 CET vr borreltijd
AD 2007-01-28 23:57:03.691 CET zo today + 5 dayish
AD 2006-01-01 00:00:00.000 CET zo yesteryear
AD 2007-01-21 23:56:42.390 CET zo mondayish
AD 1970-01-01 01:05:00.000 CET do duration + 5 minute
AD 2070-01-01 01:00:00.000 CET wo duration + 100 year
AD 2007-01-24 13:00:00.000 CET wo TZUTC today noon
AD 2007-01-24 12:00:00.000 CET wo TZEurope/Amsterdam today noon
AD 2007-01-24 01:00:00.000 CET wo TZUTC today
AD 2007-01-24 00:00:00.000 CET wo TZEurope/Amsterdam today
AD 2007-01-24 13:00:00.000 CET wo TZ UTC today noon
AD 2007-01-24 12:00:00.000 CET wo TZ Europe/Amsterdam today noon
AD 2007-01-24 01:00:00.000 CET wo TZ UTC today
AD 2007-01-24 00:00:00.000 CET wo TZ Europe/Amsterdam today
AD 1970-01-01 00:43:20.000 CET do TZ Europe/Amsterdam -1000
AD 2007-01-24 06:00:00.000 CET wo today 6 oclock
AD 2007-01-24 23:00:00.000 CET wo today 23 oclock
AD 2007-01-25 19:00:00.000 CET do today 43 oclock
AD 2007-01-24 11:16:22.000 CET wo tosecond
AD 2007-01-24 11:16:00.000 CET wo tominute
AD 2007-01-24 11:00:00.000 CET wo tohour
AD 2007-01-24 00:00:00.000 CET wo today
AD 2007-01-22 00:00:00.000 CET ma previous monday
AD 2007-01-01 00:00:00.000 CET ma tomonth
AD 2007-01-01 00:00:00.000 CET ma toyear
AD 2000-01-01 00:00:00.000 CET za tocentury
AD 2001-01-01 00:00:00.000 CET ma tocentury_pedantic
AD 0001-01-01 00:00:00.000 CET za toera
AD 2007-01-24 11:16:22.000 CET wo now this second
AD 2007-01-24 11:16:00.000 CET wo now this minute
AD 2007-01-24 11:00:00.000 CET wo now this hour
AD 2007-01-24 00:00:00.000 CET wo now this day
AD 2007-01-22 00:00:00.000 CET ma today previous monday
AD 2007-01-01 00:00:00.000 CET ma now this month
AD 2007-01-01 00:00:00.000 CET ma now this year
AD 2000-01-01 00:00:00.000 CET za now this century
AD 0001-01-01 00:00:00.000 CET za now this era
AD 2000-01-01 00:00:00.000 CET za now - 15 year this century
AD 2001-01-01 00:00:00.000 CET ma now - 20 year this century_pedantic
AD 2207-01-24 00:00:00.000 CET za today + 2 century
BC 0001-12-31 23:59:00.000 CET vr toera - 1 minute
AD 2007-07-01 00:00:00.000 CEST zo this july
AD 2006-07-01 00:00:00.000 CEST za previous july
AD 2007-07-01 00:00:00.000 CEST zo next july
AD 2007-01-28 00:00:00.000 CET zo this sunday
AD 2007-01-21 00:00:00.000 CET zo previous sunday
AD 2007-01-28 00:00:00.000 CET zo next sunday
AD 2008-12-29 00:00:00.000 CET ma 2009-W01-01
AD 2010-01-03 00:00:00.000 CET zo 2009-W53-7
AD 2006-05-03 00:00:00.000 CEST wo 2006-123
AD 2004-12-27 00:00:00.000 CET ma 2005-01-01 this monday

You can use simple strings like 'today', 'tommorrow' or 'next sunday' to enter a time to display with the tag.

<mm:time time="next sunday" format="dd MMMM yyyy" />

Will print the following depending on your locale settings:

28 January 2007

The attribute format is controlled like defined in java.util.SimpleDateFormat.
The defauls language behaviour is set in 'conf/modules/mmbaseroot.xml'. You can influence it on a page by page basis for example with the <mm:content /> tag.

1 comment

You can make the 'format' attribute completely dependent on the locale like so:
format=":FULL.FULL" for a date time representation
format=":FULL" for only a date
format=":.FULL" for only a time

And in stead of FULL more concise representation can be obtained with SHORT, MEDIUM, and LONG.

za 19 juni 2010 / mihxil' → http://www.meeuw.org

RSS feed

Tweet this article

Most mentioned links:

MMBase documentation
MMBase API
MMBase SVN
Bugtracker
MMBase Taglib reference
The reference for all tags mm