I've read I can add timezone information on an ISO8601 date by appending for example Z
or +02
or -03:00
.
I've also read that I can add timespan information by appending a P
and then the time, for example 4DT2H
(4 days and two hours).
How can I combine the two? Timezone or timespan first?
E.g. 2018-10-18T14:20+02P1D
vs 2018-10-18T14:20P1D+02
By having two values, you are basically describing when an event starts, and how long it lasts. Such values are covered in section 4.4.4.3 of the ISO 8601 specification, titled "Representations of time interval identified by start and duration".
The spec requires full compliance with the established formats for both the timestamp and the time period parts, separating them with a forward slash (/
) character.
For example: 2018-10-18T14:20+02/P1D
The time zone offset (whether Z
, or +02
, or -03:00
) belongs with the timestamp, before the slash.
That said, I know of few parsers that understand this format. It is compliant, but not every parser of ISO 8601 necessarily understands every part of the spec.