xs:dateTime Format 🔗
In XML, we generally use xs:dateTime(xs:xmlns=“http://www.w3.org/2001/XMLSchema") data type to store date time data. The generic representation of date time, that is supported by xs:dateTime in xml:
YYYY-MM-DDThh:mm:ss[.SSS][Z|(+|-)hh:mm]
Example: 🔗
2019-09-11T10:16:31.943+05:30
Code | Description | Example |
---|---|---|
YYYY | represents a 4-digit year | 2019 |
MM | represents a 2-digit month | 09 |
DD | represents 2-digit date | 11 |
hh | represents 2-digit hours | 10 |
mm | represents minutes in 2-digits | 16 |
ss | represents seconds in 2-digits | 31 |
SSS | represents milliseconds | 943 |
T | represents time separator | T |
Z | represents UTC time zone or 0 time zone offset | |
(+|-) | hh:mm represents time zone offset | +5:30 |
Few more valid examples: 2019-09-11T21:32:52, 2019-09-11T21:32:52+02:00, 2019-09-11T19:32:52Z, 2019-09-11T19:32:52+00:00, 2019-09-11T21:32:52.11179
While working with different systems, we may come across such systems, which require date time in some different formats other than default format as supported by xs:dateTime. To over come such scenarios, function is available in OIC(Oracle Integration Cloud) and Oracle SOA
Format DateTime 🔗
xp20:format-dateTime($dateTime as string, $format as string) xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20"
$dateTime should contain date time value as per xs:dateTime data type as as string eg: ‘2019-09-11T10:16:31.943+05:30’
$format should contain output format to which we need to convert to. For e.g. if we want output to be ‘11/09/2019’ then value of $format should be [D01]/[M01]/[Y001]
.
xp20:format-dateTime('2019-09-11T10:16:31.943+05:30', '[D01]/[M01]/[Y001]')
To format current date time, we can use xp20:current-dateTime() in $dateTime
xp20:format-dateTime(xp20:current-dateTime(), '[D01]/[M01]/[Y001]')
Formatting Codes: 🔗
Below are some important codes which can be helpful in generating desired format for target application.
Sample dateTime: 2019-09-03T15:16:31.943+05:30
Code | Description | Example Output |
---|---|---|
[Y001] | 4 digit year | 2019 |
[Y01] | 2 digit year | 19 |
[M01] | 2 digit month | 09 |
[D01] | 2 digit date | 03 |
[H01] | 2 digit hour in 24 hour clock | 15 |
[h01] | 2 digit hour in 12 hour clock | 03 |
[m01] | 2-digit minutes | 16 |
[s01] | 2-digit seconds | 31 |
[f001] | 3-digit milliseconds | 943 |
[Z] | Time zone offset in the form (+|-)hhmm | +0530 |
[z] | Time zone offset in the form GMT(+|-)hh:mm | GMT+05:30 |
[Dwo] | Word for ordinal value of day | third |
[dwo] | The day of the year, represented in ordinal words | second hundred and forty-sixth |
[MNn] | Capitalized month name | September |
[P] | am/pm | pm |
[PX] | Uppercase am/pm | PM |
[FNn] | Capitalized weekday name | Tuesday |
[MNn,a-b] | Capitalized month name having atleast “a” charcters and atmost “b” characters [MNn,3-3]: | Sep |