DateTime
class DateTime extends DateTime implements JsonSerializable
Extends PHP's DateTime with strict validation and additional factory methods.
Constants
| MINUTE |
minute in seconds |
| HOUR |
hour in seconds |
| DAY |
day in seconds |
| WEEK |
week in seconds |
| MONTH |
average month in seconds |
| YEAR |
average year in seconds |
Methods
Creates a DateTime object from a string, UNIX timestamp, or other DateTimeInterface object.
Creates DateTime object.
Returns a new DateTime object formatted according to the specified format.
No description
Converts a relative time string (e.g. '10 minut') to seconds.
Returns JSON representation in ISO 8601 (used by JavaScript).
Returns the date and time in the format 'Y-m-d H:i:s'.
Returns a modified copy of the object. Use (clone $dt)->modify(...) for better type safety.
Details
at line 41
static DateTime
from(string|int|DateTimeInterface|null $time)
Creates a DateTime object from a string, UNIX timestamp, or other DateTimeInterface object.
at line 63
static DateTime
fromParts(int $year, int $month, int $day, int $hour = 0, int $minute = 0, float $second = 0.0)
Creates DateTime object.
at line 82
static static|false
createFromFormat(string $format, string $datetime, string|DateTimeZone|null $timezone = null)
Returns a new DateTime object formatted according to the specified format.
at line 97
__construct(string $datetime = 'now', DateTimeZone|null $timezone = null)
No description
at line 103
DateTime
modify(string $modifier)
No description
at line 110
DateTime
setDate(int $year, int $month, int $day)
No description
at line 119
DateTime
setTime(int $hour, int $minute, int $second = 0, int $microsecond = 0)
No description
at line 136
static int
relativeToSeconds(string $relativeTime)
Converts a relative time string (e.g. '10 minut') to seconds.
at line 174
string
jsonSerialize()
Returns JSON representation in ISO 8601 (used by JavaScript).
at line 183
string
__toString()
Returns the date and time in the format 'Y-m-d H:i:s'.
at line 192
DateTime
modifyClone(string $modify = '')
Returns a modified copy of the object. Use (clone $dt)->modify(...) for better type safety.