`#[server.dateTime]`
Mule Expression Language Date and Time Functions
This reference page provides lists and brief explanations of the date and time functions in MEL.
For more information, see:
Prerequisites
This document assumes you are familiar with Mule Expression Language (MEL). Further, this document assumes you are using Mule 3.4.0 or newer.
Obtaining the Server Time
You can obtain the current date and time of the server using the context object server and one of the following fields:
-
dateTime
-
nanoTime
For example, the following expression returns the date and time of the server:
You can further specify the data you wish to extract using the following quantifiers:
-
server.dateTime.getMilliSeconds()
-
seconds
-
minutes
-
hours
-
dayOfWeek
-
dayOfMonth
-
dayOfYear
-
weekOfMonth
-
weekOfYear
-
month
-
year
The following table describes operations you can perform with dateTime. The sections below offer details on how to use the operations in MEL expressions.
Action | Operations |
---|---|
|
|
create a new DateTime instance |
|
|
|
|
|
Access timezones |
|
|
|
|
Obtain DateTime
ContextObject.Field | Description | Return Type |
---|---|---|
|
Current system date and time in a DateTime object that simplifies the parsing/formatting and very basic manipulation of dates via the Mule expression language. |
org.mule.el.datetime.DateTime |
Example:
|
||
|
Current system time in nanoseconds. Equivalent to System.nanoTime() and has the same limitations. Only use this to measure elapsed time, etc. |
int |
Example:
|
Access Partial DateTime Information
Qualifier | Description | Return Type |
---|---|---|
milliSeconds |
Returns the number of milliseconds in the current second. |
long |
Example:
|
||
seconds |
Returns the number of seconds passed in the current minute (0 to 59). |
int |
Example:
|
||
minutes |
Returns the number of minutes passed in the current hour (0 to 59). |
int |
Example:
|
||
hours |
Returns the number of hours passed in the current day (0 - 24). |
int |
Example:
|
||
|
Returns one of the following integer values:
Equivalent to calendar.get(Calendar.DAY_OF_WEEK) |
int |
Example:
|
||
|
Returns the day of the month (1 to 31). |
int |
Example:
|
||
|
Returns the day of the year (1 to 366). |
int |
Example:
|
||
|
Returns the week of the month (1 to 5). |
int |
Example:
|
||
|
Returns the week of the year (1 - 53) |
int |
Example:
|
||
|
Returns the month of the year (1 - 12) |
int |
Example:
|
||
|
Returns the the year (for example, 2013). |
int |
Example:
|
Create New DateTime Instance
Function | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|
|
Constructs a DateTime with the current time and the time zone and locale of the server. |
||||||||
Example:
|
|||||||||
|
Constructs a DateTime with the calendar and locale specified.
|
||||||||
Example:
|
|||||||||
|
Constructs a DateTime with the calendar specified and the locale of the server.
|
||||||||
Example:
|
|||||||||
|
Constructs a DateTime with the calendar specified and the locale of the server.
|
||||||||
Example: `#[calendar = javax.xml.datatype.DatatypeFactory .newInstance().newXMLGregorianCalendar(); payload = new org.mule.el.datetime.DateTime(calendar);]` |
|||||||||
|
Constructs a DateTime with the specified date and the locale and time zone of the server.
|
||||||||
Example:
|
|||||||||
|
Construct a DateTime using the specified iso8601 date.
|
||||||||
Example:
|
|||||||||
|
Constructs a DateTime using a string containing a date time in the specified format. The format should be SimpleDateFormat compatible.
|
||||||||
Example:
|
Compute Relative Dates
Functions | Description | Return Type |
---|---|---|
plusMilliSeconds(int add) |
Returns the DateTime with the given amount of milliseconds added (or subtracted if it is a negative value). |
DateTime |
plusSeconds(int add) |
Returns the DateTime with the given amount of seconds added (or subtracted if it is a negative value). |
DateTime |
plusMinutes(int add) |
Returns the DateTime with the given amount of minutes added (or subtracted if it is a negative value). |
DateTime |
plusHours(int add) |
Returns the DateTime with the given amount of hours added (or subtracted if it is a negative value). |
DateTime |
plusDays(int add) |
Returns the DateTime with the given amount of days added (or subtracted if it is a negative value). |
DateTime |
plusWeeks(int add) |
Returns the DateTime with the given amount of weeks added (or subtracted if it is a negative value). |
DateTime |
plusMonths(int add) |
Returns the DateTime with the given amount of months added (or subtracted if it is a negative value). |
DateTime |
plusYears(int add) |
Returns the DateTime with the given amount of years added (or subtracted if it is a negative value). |
DateTime |
Example
#[payload = 'Two days ago it was the ' + server.dateTime.plusDays(-2).dayOfWeek + 'st day of the week';]
Compare
Function | Description | Return Type |
---|---|---|
|
Returns whether this Calendar represents a time before the instant represented by the specified argument. |
boolean |
Example:
|
||
|
Returns whether this Calendar represents a time after the instant represented by the specified argument. |
boolean |
Example:
|
Access Timezones
Function | Description | Return Type | ||||
---|---|---|---|---|---|---|
|
Changes only the timezone of the instance.
|
DateTime |
||||
Example: `#[pstTimeZoneInstant = server.dateTime.withTimeZone('PST');] #[phoenixInstant = server.dateTime.withTimeZone('America/Phoenix');]` |
||||||
|
Changes the timezone of the instance, and then changes the current DateTime to match the updated timezone.
|
DateTime |
||||
Example: `#[pstTimeZoneInstant = server.dateTime.withTimeZone('PST');] #[phoenixInstant = server.dateTime.changeTimeZone('America/Phoenix');]` |
||||||
|
Returns the current TimeZone of the dateTime instance. |
string |
||||
Example:
|
||||||
|
This method takes the string format of a locale and creates the locale object from it.
|
DateTime |
||||
Example:
|
Format Strings
Function | Description | Return Type | ||||
---|---|---|---|---|---|---|
|
Formats the instance in a string with the ISO8601 date time format. |
string |
||||
Example:
|
||||||
|
Formats the instance in a specific format.
|
string |
||||
Example:
|
When writing in Studio’s XML editor, you cannot use double quotes to express String literals, because MEL expressions already appear enclosed in double quotes in configuration files. Instead, you can either:
If you’re writing on Studio’s visual editor, double quotes transform into escaped quotes` ("`) in the XML view. |
Transform
Function | Description | Return Type | ||
---|---|---|---|---|
|
Returns a Java Calendar representation of the dateTime instance. |
Calendar |
||
Example:
|
||||
|
Returns a Java Date representation of the datetime instance. |
java.util.Date |
||
Example:
|
||||
|
Returns a XMLCalendar representation of the datetime instance.
|
XMLGregorianCalendar |
||
Example:
|
See Also
-
Learn more about the Mule Expression Language (MEL).