DateValues object

DateValues is an object that can be used in Spring EL to work with dates, it provides methods to get specific dates, modify them and to write them to and from text.

For a good overview see the code example.

DateValues properties and methods

All DateValues properties return a DateWrapper object.

#{date.parse( 'yyyy-MM-dd' )}

Converts a date in year-month-day format to a DateWrapper instance. The supported formats are:

  • yyyy-MM-dd
  • yyyy-MM-dd HH:mm
  • yyyy-MM-dd HH:mm:ss

For more information on format strings, see http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html

#{date.now}Returns current date and time.
#{date.today}Returns midnight of the current date.
#{date.tomorrow}Returns current date and time + 1 day.
#{date.yesterday}Returns current date and time - 1 day.
#{date.thisMonth}Returns midnight of the first day of the current month.
#{date.nextMonth}Returns current date and time + 1 month.
#{date.lastMonth}Returns current date and time - 1 month.
#{date.thisYear}Returns midnight of January 1st of this year.
#{date.nextYear}Returns current date and time + 1 year. Returns midnight of January 1st of next year.
#{date.lastYear}Returns current date and time - 1 year. Returns midnight of January 1st of last year.
#{date.today.addYears(-4)}Returns the same day and month four years ago

#{date.nextMonday}

#{date.nextTuesday}

#{date.nextWednesday}

#{date.nextThursday}

#{date.nextFriday}

#{date.nextSaturday}

#{date.nextSunday}

Returns the same time on the next day of the week specified. The current day of the week is not taken into account.

#{date.lastMonday}

#{date.lastTuesday}

#{date.lastWednesday}

#{date.lastThursday}

#{date.lastFriday}

#{date.lastSaturday}

#{date.lastSunday}

Returns the same time on the previous day of the week specified. The current day of the week is not taken into account.

DateWrapper properties and methods

#{x.format( 'yyyy-MM-dd' )}

Formats the date according to the pattern specified.

For more information on format strings, see http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html

#{x.before( y )}Returns true if date X falls before date Y. This is in fact the same as #{x < y}.
#{x.after( y )}Returns true if date X falls after date Y. This is in fact the same as #{x > y}.
#{x.day}Returns the day in the month.
#{x.month}Returns the number of the month (January = 1).
#{x.year}Returns the year.
#{x.hour}Returns the hour of day (0..23).
#{x.minute}Returns the minute of the hour.
#{x.second}Returns the second of the minut.
#{x.week}Returns the number of the week in the year (week starts at Monday).
#{x.dayOfWeek}

Returns the day of the week as a number:

sunday1
monday2
tuesday3
wednesday4
thursday5
friday6
saturday7
#{x.dayOfYear}Returns the day of the year.
#{x.addDays(y)}Adds the number of days to the given date and returns a new date.
#{x.addDays(y, allowedDays)}

Adds the number of days to the given date and returns a new date. Only the weekdays in the allowedDays list are taken into account for the amount.

The allowedDays option is a comma separate list of weekdays in English (shorthand notation is allowed).

Example: adding 5 working days
 #{date.addDays(5, 'mon,tue,wed,thu,fri')}
#{x.addMonths(y)}Adds the number of months to the given date and returns a new date.
#{x.addYears(y)}Adds the number of years to the given date and returns a new date.
#{x.addHours(y)}Adds the number of hours to the given date and returns a new date.
#{x.addMinutes(y)}Adds the number of minutes to the given date and returns a new date.
#{x.addSeconds(y)}Adds the number of seconds to the given date and returns a new date.
#{x.addWeeks(y)}Adds the number of weeks to the given date and returns a new date.

#{x.nextMonday}

#{x.nextTuesday}

#{x.nextWednesday}

#{x.nextThursday}

#{x.nextFriday}

#{x.nextSaturday}

#{x.nextSunday}

Returns the same time on the next day of the week specified. The day of the week of the current date (x) is not taken into account.

#{x.lastMonday}

#{x.lastTuesday}

#{x.lastWednesday}

#{x.lastThursday}

#{x.lastFriday}

#{x.lastSaturday}

#{x.lastSunday}

Returns the same time on the previous day of the week specified. The day of the week of the current date (x) is not taken into account.
#{x.thisMonth}Returns midnight of the first day of the month in which the current date falls.
#{x.thisYear}Returns midnight of January 1st of the year in which the current date falls.