JSONDateTime
extends SerializableDateTime
in package
DateTime serializer for JSON responses.
Formats DateTime objects as ISO 8601 strings with microsecond precision and timezone information, suitable for JSON API responses.
Format: 2025-12-07T14:30:45.123456+00:00
Tags
Table of Contents
Methods
- fromDT() : static
- Create a SerializableDateTime from an existing DateTime instance.
- fromString() : static
- jsonSerialize() : string
- Serialize this DateTime for JSON encoding.
- marshall() : string
- Convert this DateTime to a formatted string.
- parse() : static
- Parse a formatted date string into this DateTime.
- getFormat() : string
- Get the DateTime format string for JSON serialization.
Methods
fromDT()
Create a SerializableDateTime from an existing DateTime instance.
public
static fromDT(DateTime $dt) : static
Convenient factory method for converting existing DateTime objects.
Parameters
- $dt : DateTime
-
The source DateTime.
Return values
static —A new instance with the same timestamp as $dt.
fromString()
public
static fromString(string $data) : static
Parameters
- $data : string
Return values
staticjsonSerialize()
Serialize this DateTime for JSON encoding.
public
jsonSerialize() : string
Implements JsonSerializable to enable json_encode() on Obj instances containing DateTime fields.
Return values
string —The formatted date/time string (via marshall()).
marshall()
Convert this DateTime to a formatted string.
public
marshall() : string
Called during serialization when this DateTime appears in an Obj field.
Return values
string —The formatted date/time string.
parse()
Parse a formatted date string into this DateTime.
public
parse(mixed $data) : static
Called during deserialization when a string is provided for a DateTime field.
Parameters
- $data : mixed
-
The date string to parse (should match getFormat()).
Tags
Return values
static —This instance, updated with the parsed timestamp.
getFormat()
Get the DateTime format string for JSON serialization.
protected
static getFormat() : string
Return values
string —ISO 8601 format with microseconds and timezone.