JsonDateTimeFormat Enumeration

Specifies how DateTime, DateTimeOffset and DateOnly instances are formatted and parsed by the JsonValueExtensions methods.

Definition

Namespace: KGySoft.Json
Assembly: KGySoft.Json (in KGySoft.Json.dll) Version: 3.0.0
C#
public enum JsonDateTimeFormat

Members

Auto0

When converting a DateTime or DateTimeOffset instance to JSON, it is equivalent to the Iso8601JavaScript format if the target Type is String, or the UnixMilliseconds format if the target Type is Number.

When converting a DateOnly instance to JSON, it is equivalent to the Iso8601Date format if the target Type is String, or the UnixMilliseconds format if the target Type is Number.

When parsing a JsonValue, it represents any defined JsonDateTimeFormat, including some ISO 8601 formats, which are not covered by the other values in the JsonDateTimeFormat enumeration.

Note: Parsing a date-time value with the Auto option from a JSON Number can be ambiguous (see the UnixMilliseconds, UnixSeconds, UnixSecondsFloat and Ticks formats). Though a "sanity check" is applied for parsing such values use a specific option whenever possible.

UnixMilliseconds1

Represents the time elapsed since the Unix Epoch time (1970-01-01T00:00Z) in milliseconds. This is conform with the constructor of the Date object and also with its getTime method in JavaScript.

When converting to JSON, local times will be adjusted to UTC. When parsing, the value is interpreted as UTC time.

Example: 2020-01-01T00:00+01:00 becomes 1577833200000

UnixSeconds2

Represents the time elapsed since the Unix Epoch time (1970-01-01T00:00Z) in seconds.

When converting to JSON, local times will be adjusted to UTC. When parsing, the value is interpreted as UTC time.

Example: 2020-01-01T00:00+01:00 becomes 1577833200

UnixSecondsFloat3

Represents the time elapsed since the Unix Epoch time (1970-01-01T00:00Z) in seconds as a floating point number.

When converting to JSON, local times will be adjusted to UTC. When parsing, the value is interpreted as UTC time.

Example: 2020-01-01T00:00+01:00 becomes 1577833200.000

Ticks4

Represents the time elapsed since 0001-01-01T00:00Z in 100 nanoseconds, in UTC. This is conform with the constructor of the .NET DateTime type and its Ticks property.

When converting to JSON, local times will be adjusted to UTC. When parsing, the value is interpreted as UTC time.

Example: 2020-01-01T00:00+01:00 becomes 637134300000000000

Iso8601JavaScript5

Represents an ISO 8601 conform date/time format in UTC, as it is returned by the toJSON method of the JavaScript Date object prototype by most of the recent JavaScript implementations.

When converting to JSON, local times will be adjusted to UTC. When parsing, the value is interpreted as UTC time.

Example: 2020-01-01T00:00+01:00 becomes 2019-12-31T23:00:00.000Z

Iso8601Roundtrip6

Represents an ISO 8601 conform date/time, which can encode .NET DateTime and DateTimeOffset instances without losing precision. It can be parsed also by JavaScript, although the time value beyond milliseconds precision might be lost.

When converting a DateTime instance to JSON, the DateTime.Kind is also reflected in the result, which is restored on parsing.

A DateTimeOffset is always treated as a local time of the time zone specified by its offset. You can obtain its UtcDateTime property to encode it as a UTC time.

A DateOnly instance is always formatted without time and zone information.

Examples:

Iso8601Utc7

Represents an ISO 8601 conform date/time format in UTC, which can encode .NET DateTime and DateTimeOffset instances without losing precision. It can be parsed also by JavaScript, although the time value beyond milliseconds precision might be lost.

When converting to JSON, local times will be adjusted to UTC. When parsing, the value is interpreted as UTC time.

Example: 2020-01-01T00:00+01:00 becomes 2019-12-31T23:00:00.0000000Z

Iso8601Local8

Represents an ISO 8601 conform date/time format with time zone, which can encode .NET DateTime and DateTimeOffset instances without losing precision. It can be parsed also by JavaScript, although the time value beyond milliseconds precision might be lost.

When converting to JSON, DateTime instances with Utc Kind will be adjusted to local time. When parsing as DateTime, the value will be adjusted to the actual local time.

Example: 2020-01-01T00:00+01:00 becomes 2020-01-01T00:00:00.0000000+01:00

Iso8601Date9

Represents an ISO 8601 conform date, without time and time zone information.

When converting a DateTime instance to JSON, the Kind property is ignored and the time value is not adjusted. When parsing as a DateTime the Kind will be Unspecified by default.

A DateTimeOffset is always treated as a local time of the time zone specified by its offset. You can obtain its UtcDateTime property to encode it as a UTC date.

Example: 2020-01-01T00:00+01:00 becomes 2020-01-01

Iso8601Minutes10

Represents an ISO 8601 conform date/time with hours and minutes.

When converting a DateTime instance to JSON, the DateTime.Kind is also reflected in the result, which is restored on parsing.

A DateTimeOffset is always treated as a local time of the time zone specified by its offset. You can obtain its UtcDateTime property to encode it as a UTC time.

A DateOnly instance is always formatted with zero time and without time zone information.

Examples:

Iso8601Seconds11

Represents an ISO 8601 conform date/time with hours, minutes and seconds.

When converting a DateTime instance to JSON, the DateTime.Kind is also reflected in the result, which is restored on parsing.

A DateTimeOffset is always treated as a local time of the time zone specified by its offset. You can obtain its UtcDateTime property to encode it as a UTC time.

A DateOnly instance is always formatted with zero time and without time zone information.

Examples:

Iso8601Milliseconds12

Represents an ISO 8601 conform date/time with milliseconds precision. Similar to the Iso8601JavaScript format, except that this one does not convert local times to UTC.

When converting a DateTime instance to JSON, the DateTime.Kind is also reflected in the result, which is restored on parsing.

A DateTimeOffset is always treated as a local time of the time zone specified by its offset. You can obtain its UtcDateTime property to encode it as a UTC time.

A DateOnly instance is always formatted with zero time and without time zone information.

Examples:

MicrosoftLegacy13

Represents Microsoft's legacy AJAX and WCF REST date-time format. Similarly to UnixMilliseconds, it is also based on elapsed milliseconds since Unix Epic time but has a specific string format and can also encode a time offset.

Examples:

See Also