Date & Time
current-time()
The current system time
current-time()
current-unixTime()
The current system time shown as milliseconds since the epoch
current-unixTime()
format-date()
The format-date() function combines parsing and formatting of date strings. In its simplest form it will parse a date string and return the parsed date in the XML standard Date Format. It also supports supplying a custom format pattern to output the parsed date in a specified format.
Function Signatures
The following are the possible forms of the format-date function.
<!-- Convert time in millis to standard date format -->
format-date(long millisSinceEpoch)
<!-- Convert inputDate to standard date format -->
format-date(String inputDate, String inputPattern)
<!-- Convert inputDate to standard date format using specified input time zone -->
format-date(String inputDate, String inputPattern, String inputTimeZone)
<!-- Convert inputDate to a custom date format using optional input time zone inputTimeZone -->
format-date(String inputDate, String inputPattern, String inputTimeZone, String outputPattern)
<!-- Convert inputDate to a custom date format using optional input time zone and a specified output time zone -->
format-date(String inputDate, String inputPattern, String inputTimeZone, String outputPattern, String outputTimeZone)
millisSinceEpoch- The date/time expressed as the number of milliseconds since the UNIX epoch .inputDate- The input date string, e.g.2009/08/01 12:34:11.inputPattern- The pattern that defines the structure ofinputDate(see Custom Date Formats).inputTimeZone- Optional time zone of theinputDate. Ifnullthen the UTC/Zulu time zone will be used. IfinputTimeZoneis present, the inputPattern must not include the time zone pattern tokens (zandZ).outputPattern- The pattern that defines the format of the output date (see Custom Date Formats).outputTimeZone- Optional time zone of the output date. Ifnullthen the UTC/Zulu time zone will be used.
Time Zones
The following is a list of some common time zone values:
| Values | Zone Name |
|---|---|
GMT/BST |
A Stroom specific value for UK daylight saving time (see below) |
UTC, UCT, Zulu, Universal, +00:00, -00:00, +00, +0 |
Coordinated Universal Time (UTC) |
GMT, GMT0, Greenwich |
Greenwich Mean Time (GMT) |
GB, GB-Eire, Europe/London |
British Time |
NZ, Pacific/Auckland |
New Zealand Time |
Australia/Canberra, Australia/Sydney |
Eastern Australia Time |
CET |
Central European Time |
EET |
Eastern European Time |
Canada/Atlantic |
Atlantic Time |
Canada/Central |
Central Time |
Canada/Pacific |
Pacific Time |
US/Central |
Central Time |
US/Eastern |
Eastern Time |
US/Mountain |
Mountain Time |
US/Pacific |
Pacific Time |
+02:00, +02, +2 |
UTC +2hrs |
-03:00, -03, -3 |
UTC -3hrs |
A special time zone value of GMT/BST can be used when the inputDate is in local wall clock time with time zone information.
In this case, the date/time will be used to determine whether the date is in British Summer Time or in GMT and adjust the output accordingly.
See the examples below.
Parsing Examples
The following table shows various examples of calls to stroom:format-date() with their output.
The stroom:format-date part has been omitted for brevity.
<!-- Date in millis since UNIX epoch -->
stroom:format-date('1269270011640')
-> '2010-03-22T15:00:11.640Z'
<!-- Simple date UK style date -->
stroom:format-date('29/08/24', 'dd/MM/yy')
-> '2024-08-29T00:00:00.000Z'
<!-- Simple date US style date -->
stroom:format-date('08/29/24', 'MM/dd/yy')
-> '2024-08-29T00:00:00.000Z'
<!-- ISO date with no delimiters -->
stroom:format-date('20010801184559', 'yyyyMMddHHmmss')
-> '2001-08-01T18:45:59.000Z'
<!-- Standard output, no TZ -->
stroom:format-date('2001/08/01 18:45:59', 'yyyy/MM/dd HH:mm:ss')
-> '2001-08-01T18:45:59.000Z'
<!-- Standard output, date only, with TZ -->
stroom:format-date('2001/08/01', 'yyyy/MM/dd', '-07:00')
-> '2001-08-01T07:00:00.000Z'
<!-- Standard output, with TZ -->
stroom:format-date('2001/08/01 01:00:00', 'yyyy/MM/dd HH:mm:ss', '-08:00')
-> '2001-08-01T09:00:00.000Z'
<!-- Standard output, with TZ -->
stroom:format-date('2001/08/01 01:00:00', 'yyyy/MM/dd HH:mm:ss', '+01:00')
-> '2001-08-01T00:00:00.000Z'
<!-- Single digit day and month, no padding -->
stroom:format-date('2001 8 1', 'yyyy MM dd')
-> '2001-08-01T00:00:00.000Z'
<!-- Double digit day and month, no padding -->
stroom:format-date('2001 12 28', 'yyyy MM dd')
-> '2001-12-28T00:00:00.000Z'
<!-- Single digit day and month, with optional padding -->
stroom:format-date('2001 8 1', 'yyyy ppMM ppdd')
-> '2001-08-01T00:00:00.000Z'
<!-- Double digit day and month, with optional padding -->
stroom:format-date('2001 12 31', 'yyyy ppMM ppdd')
-> '2001-12-31T00:00:00.000Z'
<!-- With abbreviated day of week month -->
stroom:format-date('Wed Aug 14 2024', 'EEE MMM dd yyyy')
-> '2024-08-14T00:00:00.000Z'
<!-- With long form day of week and month -->
stroom:format-date('Wednesday August 14 2024', 'EEEE MMMM dd yyyy')
-> '2024-08-14T00:00:00.000Z'
<!-- With 12 hour clock, AM -->
stroom:format-date('Wed Aug 14 2024 10:32:58 AM', 'E MMM dd yyyy hh:mm:ss a')
-> '2024-08-14T10:32:58.000Z'
<!-- With 12 hour clock, PM (lower case) -->
stroom:format-date('Wed Aug 14 2024 10:32:58 pm', 'E MMM dd yyyy hh:mm:ss a')
-> '2024-08-14T22:32:58.000Z'
<!-- Using minimal symbols -->
stroom:format-date('2001 12 31 22:58:32.123', 'y M d H:m:s.S')
-> '2001-12-31T22:58:32.123Z'
<!-- Optional time portion, with time -->
stroom:format-date('2001/12/31 22:58:32.123', 'yyyy/MM/dd[ HH:mm:ss.SSS]')
-> '2001-12-31T22:58:32.123Z'
<!-- Optional time portion, without time -->
stroom:format-date('2001/12/31', 'yyyy/MM/dd[ HH:mm:ss.SSS]')
-> '2001-12-31T00:00:00.000Z'
<!-- Optional millis portion, with millis -->
stroom:format-date('2001/12/31 22:58:32.123', 'yyyy/MM/dd HH:mm:ss[.SSS]')
-> '2001-12-31T22:58:32.123Z'
<!-- Optional millis portion, without millis -->
stroom:format-date('2001/12/31 22:58:32', 'yyyy/MM/dd HH:mm:ss[.SSS]')
-> '2001-12-31T22:58:32.000Z'
<!-- Optional millis/nanos portion, with nanos -->
stroom:format-date('2001/12/31 22:58:32.123456', 'yyyy/MM/dd HH:mm:ss[.SSS]')
-> '2001-12-31T22:58:32.123Z'
<!-- Fixed text -->
stroom:format-date('Date: 2001/12/31 Time: 22:58:32.123', ''Date: 'yyyy/MM/dd 'Time: 'HH:mm:ss.SSS')
-> '2001-12-31T22:58:32.123Z'
<!-- GMT/BST date that is BST -->
stroom:format-date('2009/06/01 12:34:11', 'yyyy/MM/dd HH:mm:ss', 'GMT/BST')
-> '2009-06-01T11:34:11.000Z'
<!-- GMT/BST date that is GMT -->
stroom:format-date('2009/02/01 12:34:11', 'yyyy/MM/dd HH:mm:ss', 'GMT/BST')
-> '2009-02-01T12:34:11.000Z'
<!-- Time zone offset -->
stroom:format-date('2009/02/01 12:34:11', 'yyyy/MM/dd HH:mm:ss', '+01:00')
-> '2009-02-01T11:34:11.000Z'
<!-- Named time zone -->
stroom:format-date('2009/02/01 23:34:11', 'yyyy/MM/dd HH:mm:ss', 'US/Eastern')
-> '2009-02-02T04:34:11.000Z'
Note
Parsing is done in lenient mode so, the count of each symbol is not critical, e.g. you can parse the year 2024 with y, yy, yyy or yyyy.
Despite this, it is advisable to use a pattern that matches the known format of the input dates, e.g. in this example yyyy, to avoid confusing with anyone else reading your XSLT.
The count of each symbol is however critical when it comes to formatting.
Formatting Examples
<!-- Specific output, no input or output TZ -->
stroom:format-date('2001/08/01 14:30:59', 'yyyy/MM/dd HH:mm:ss', null, 'E dd MMM yyyy HH:mm (s 'secs')')
-> 'Wed 01 Aug 2001 14:30 (59 secs)'
<!-- Specific output, UTC input, no output TZ -->
stroom:format-date('2001/08/01 14:30:59', 'yyyy/MM/dd HH:mm:ss', 'UTC', 'E dd MMM yyyy HH:mm (s 'secs')')
-> 'Wed 01 Aug 2001 14:30 (59 secs)'
<!-- Specific output, no output TZ -->
stroom:format-date('2001/08/01 14:30:59', 'yyyy/MM/dd HH:mm:ss', '+01:00', 'E dd MMM yyyy HH:mm (s 'secs')')
-> 'Wed 01 Aug 2001 13:30 (59 secs)'
<!-- Specific output, with input and output TZ -->
stroom:format-date('2001/08/01 14:30:59', 'yyyy/MM/dd HH:mm:ss', '+01:00', 'E dd MMM yyyy HH:mm', '+02:00')
-> 'Wed 01 Aug 2001 15:30'
<!-- Padded 12 hour clock output -->
stroom:format-date('2001/08/01 14:07:05.123', 'yyyy/MM/dd HH:mm:ss.SSS', 'UTC', 'E dd MMM yyyy pph:ppm:pps a')
-> 'Wed 01 Aug 2001 2: 7: 5 PM'
<!-- Padded 12 hour clock output -->
stroom:format-date('2001/08/01 22:27:25.123', 'yyyy/MM/dd HH:mm:ss.SSS', 'UTC', 'E dd MMM yyyy pph:ppm:pps a')
-> 'Wed 01 Aug 2001 10:27:25 PM'
<!-- Non-Padded 12 hour clock output -->
stroom:format-date('2001/08/01 14:07:05.123', 'yyyy/MM/dd HH:mm:ss.SSS', 'UTC', 'E dd MMM yyyy h:m:s a')
-> 'Wed 01 Aug 2001 2:7:5 PM'
<!-- Long form text -->
stroom:format-date('2001/08/01 14:07:05.123', 'yyyy/MM/dd HH:mm:ss.SSS', 'UTC', 'EEEE d MMMM yyyy HH:mm:ss')
-> 'Wednesday 1 August 2001 14:07:05'
Reference Time
When parsing a date string that does not contain a full zoned date and time, certain assumptions will be made.
If there is no time zone in inputDate and no inputTimeZone argument has been passed then the time zone of the input date will be assumed to be in the UTC time zone.
If any of the date parts are not present, e.g. an input of 28 Oct then Stroom will use a reference date to fill in the gaps.
The reference date is the first of these values that is non-null
- The create time of the stream being processed by the XSLT.
- The current time, i.e. now().
For example for a call of stroom:format-date('28 Oct', 'dd MMM') and a stream create time of 2024, it will return 2024-10-28T00:00:00.000Z.
format-dateTime()
Formats the dateTime as a string according to the specified pattern and time zone.
Function Signatures
The following are the possible forms of the format-dateTime function.
<!-- Format dateTime to standard date format -->
format-dateTime(DateTime dateTime)
<!-- Format dateTime to a custom date format-->
format-dateTime(DateTime dateTime, String pattern)
<!-- Convert dateTime to standard date format using specified input time zone -->
format-dateTime(DateTime dateTime, String pattern, String timeZone)
dateTime- The input dateTime.pattern- The pattern that defines the format of the output string (see Custom Date Formats).timeZone- Optional time zone of the output. Ifnullthen the UTC/Zulu time zone will be used.
Examples
<!-- Default format -->
stroom:format-dateTime(xs:dateTime('2024-08-29T00:00:00Z'))
-> '2024-08-29T00:00:00.000Z'
<!-- Default format +2hr zone offset -->
stroom:format-dateTime(xs:dateTime('2001-08-01T18:45:59.123+02:00'))
-> '2001-08-01T16:45:59.123Z'
<!-- Default format +2hr30min zone offset -->
stroom:format-dateTime(xs:dateTime('2001-08-01T18:45:59.123+02:30'))
-> '2001-08-01T16:15:59.123Z'
<!-- Default format -3hr zone offset -->
stroom:format-dateTime(xs:dateTime('2001-08-01T18:45:59.123-03:00'))
-> '2001-08-01T21:45:59.123Z'
<!-- Simple date format UK style date -->
stroom:format-dateTime(xs:dateTime('2024-08-29T00:00:00Z'), 'dd/MM/yy')
-> '29/08/24'
<!-- Simple date format US style date -->
stroom:format-dateTime(xs:dateTime('2024-08-29T00:00:00Z'), 'MM/dd/yy')
-> '08/29/24'
<!-- With no delimiters -->
stroom:format-dateTime(xs:dateTime('2001-08-01T18:45:59Z'), 'yyyyMMddHHmmss')
-> '20010801184559'
<!-- Standard output, no TZ -->
stroom:format-dateTime(xs:dateTime('2001-08-01T18:45:59Z'), 'yyyy/MM/dd HH:mm:ss')
-> '2001/08/01 18:45:59'
<!-- Format with nanos -->
stroom:format-dateTime(xs:dateTime('2010-01-01T23:59:59.123456Z'), 'yyyy-MM-dd'T'HH:mm:ss.SSSSSSXX')
-> '2010-01-01T23:59:59.123456Z'
<!-- Standard output, with TZ -->
stroom:format-dateTime(xs:dateTime('2001-08-01T09:00:00Z'), 'yyyy/MM/dd HH:mm:ss', '-08:00')
-> '2001/08/01 01:00:00'
<!-- Standard output, with TZ -->
stroom:format-dateTime(xs:dateTime('2001-08-01T00:00:00Z'), 'yyyy/MM/dd HH:mm:ss', '+01:00')
-> '2001/08/01 01:00:00'
<!-- GMT/BST date that is BST -->
stroom:format-dateTime(xs:dateTime('2009-06-01T11:34:11Z'), 'yyyy/MM/dd HH:mm:ss', 'GMT/BST')
-> '2009/06/01 12:34:11'
<!-- GMT/BST date that is GMT -->
stroom:format-dateTime(xs:dateTime('2009-02-01T12:34:11Z'), 'yyyy/MM/dd HH:mm:ss', 'GMT/BST')
-> '2009/02/01 12:34:11'
<!-- Named time zone -->
stroom:format-dateTime(xs:dateTime('2009-02-02T04:34:11Z'), 'yyyy/MM/dd HH:mm:ss', 'US/Eastern')
-> '2009/02/01 23:34:11'
from-unixTime()
Returns the specified number of milliseconds since the epoch as a dateTime
from-unixTime(Integer milliseconds)
parse-dateTime()
Parses a string to a dateTime according to the specified pattern and time zone.
Function Signatures
The following are the possible forms of the parse-dateTime function.
<!-- Converts inputDate to a dateTime -->
parse-dateTime(String inputDate)
<!-- Converts inputDate to a dateTime using a custom date format -->
parse-dateTime(DateTime inputDate, String pattern)
<!-- Converts inputDate to a dateTime using a custom date format in the specified time zone -->
parse-dateTime(DateTime inputDate, String pattern, String timeZone)
inputDate- The input string.pattern- The pattern that defines the format of the input string (see Custom Date Formats).timeZone- Optional time zone of the output. Ifnullthen the UTC/Zulu time zone will be used.
Examples
<!-- ISO 8061 -->
stroom:parse-dateTime('2024-08-29T00:00:00Z')
-> '2024-08-29T00:00:00Z'
<!-- ISO 8061 with nanos -->
stroom:parse-dateTime('2010-01-01T23:59:59.123456Z')
-> '2010-01-01T23:59:59.123456Z'
<!-- ISO 8061 with millis -->
stroom:parse-dateTime('2010-01-01T23:59:59.123Z')
-> '2010-01-01T23:59:59.123Z'
<!-- ISO 8061 Zulu/UTC -->
stroom:parse-dateTime('2001-08-01T18:45:59.123+00:00')
-> '2001-08-01T18:45:59.123Z'
<!-- ISO 8061 +2hr zone offset -->
stroom:parse-dateTime('2001-08-01T18:45:59.123+02')
-> '2001-08-01T16:45:59.123Z'
<!-- ISO 8061 +2hr zone offset -->
stroom:parse-dateTime('2001-08-01T18:45:59.123+02:00')
-> '2001-08-01T16:45:59.123Z'
<!-- ISO 8061 +2hr30min zone offset -->
stroom:parse-dateTime('2001-08-01T18:45:59.123+02:30')
-> '2001-08-01T16:15:59.123Z'
<!-- ISO 8061 -3hr zone offset -->
stroom:parse-dateTime('2001-08-01T18:45:59.123-03:00')
-> '2001-08-01T21:45:59.123Z'
<!-- Simple date UK style date -->
stroom:parse-dateTime('29/08/24', 'dd/MM/yy')
-> '2024-08-29T00:00:00Z'
<!-- Simple date US style date -->
stroom:parse-dateTime('08/29/24', 'MM/dd/yy')
-> '2024-08-29T00:00:00Z'
<!-- ISO date with no delimiters -->
stroom:parse-dateTime('20010801184559', 'yyyyMMddHHmmss')
-> '2001-08-01T18:45:59Z'
<!-- Standard output, no TZ -->
stroom:parse-dateTime('2001/08/01 18:45:59', 'yyyy/MM/dd HH:mm:ss')
-> '2001-08-01T18:45:59Z'
<!-- Standard output, date only, with TZ -->
stroom:parse-dateTime('2001/08/01', 'yyyy/MM/dd', '-07:00')
-> '2001-08-01T07:00:00Z'
<!-- Standard output, with TZ -->
stroom:parse-dateTime('2001/08/01 01:00:00', 'yyyy/MM/dd HH:mm:ss', '-08:00')
-> '2001-08-01T09:00:00Z'
<!-- Standard output, with TZ -->
stroom:parse-dateTime('2001/08/01 01:00:00', 'yyyy/MM/dd HH:mm:ss', '+01:00')
-> '2001-08-01T00:00:00Z'
to-unixTime()
Returns milliseconds since the epoch for a specified dateTime
to-unixTime(DateTime dateTime)