Patterns for Offset values

The Offset type supports the following patterns:

Standard Patterns

The following standard patterns are supported:

  • l: Long format, displaying information down to the second. Typical pattern text: +HH:mm:ss
  • m: Medium format, displaying information down to the minute. Typical pattern text: +HH:mm
  • s: Short format, displaying information down to the hour. Typical pattern text: +HH
  • L: Long format without punctuation, displaying information down to the second. Typical pattern text: +HHmmss
  • M: Medium format without punctuation, displaying information down to the minute. Typical pattern text: +HHmm
  • S: Short format without punctuation, displaying information down to the hour. Typical pattern text: +HH (so equivalent to s in many cases, but can vary by culture)
  • g: General pattern. Formatting depends on the value passed in. If the offset has seconds, the long format is used; otherwise, if the offset has minutes, the medium format is used; otherwise the short format is used. When parsing, the other standard format patterns are tried one at a time. This is the default format pattern.
  • G: As g, but using Z for an offset of 0, as if it were Z-prefixed. (See below.)
  • i: As g, but using the colon-free formats (L, M, S)
  • I: As i, but using Z for an offset of 0, as if it were Z-prefixed. (See below.)

Custom Patterns

The following custom pattern characters are supported for offsets. See custom pattern notes for general notes on custom patterns, including characters used for escaping and text literals.

Character Meaning Example
Z This can only occur at the start of a pattern, as a prefix to a normal pattern. When it's used, an offset of zero is always formatted as "Z", and "Z" will be parsed as a zero offset. When formatting, a non-zero offset falls back to the remainder of the pattern. When parsing, a non-Z value is always parsed by the remainder of the pattern, and a result of a zero offset is still acceptable. (So a pattern of "ZHH:mm" can still parse a value of "00:00" even though it would be formatted as "Z".) Zero: ZHH:mm => Z
5 hours: ZHH:mm => 05:00
H or HH Number of hours in the offset. HH is zero-padded; H is not. H:mm => 7:30
HH:mm => 07:30
m or mm Number of minutes within the hour. mm is zero-padded; m is not. 5 minutes: m:ss => 5:00
5 minutes: mm:ss => 05:00
s or ss Number of seconds within the minute. ss is zero-padded; s is not. 5 seconds: s => 5
5 seconds: ss => 05
+ The sign of the value, always specified whether positive or negative. + and - are always used as the symbols, regardless of the culture used when constructing the pattern. A positive offset is used when local time is ahead of UTC (e.g. Europe) and a negative offset is used when local time is behind UTC (e.g. America). Positive value: +HH:mm => +07:30
Negative value: +HH:mm => -07:30
- The sign of the value, only specified when the value is negative. + and - are always used as the symbols, regardless of the culture used when constructing the pattern. Positive value: -HH:mm => 07:30
Negative value: -HH:mm => -07:30
: The time separator for the format provider; colon in the invariant culture. HH:mm => 07:30