DateTime
class DateTime extends DateTime implements JsonSerializable (View source)
A simple DateTime wrapper with predefined formats which supports stringification and JSON.
Constants
ATOM |
|
COOKIE |
|
ISO8601 |
|
RFC822 |
|
RFC850 |
|
RFC1036 |
|
RFC1123 |
|
RFC2822 |
|
RFC3339 |
|
RFC3339_EXTENDED |
|
RFC7231 |
|
RSS |
|
W3C |
|
Properties
string | $format | The default format of any date/time type automatically converted by pq\Result (depends on the actual type of the column). |
Methods
Alter the timestamp of a DateTime object by incrementing or decrementing in a format accepted by strtotime().
Adds an amount of days, months, years, hours, minutes and seconds to a DateTime object
Subtracts an amount of days, months, years, hours, minutes and seconds from a DateTime object
Sets the current time of the DateTime object to a different time.
Sets the current date of the DateTime object to a different date.
Set a date according to the ISO 8601 standard - using weeks and day offsets rather than specific dates.
Sets the date and time based on a Unix timestamp.
Returns the difference between two DateTime objects represented as a DateInterval.
Parse a string into a new DateTime object according to the specified format
Returns an array of warnings and errors found while parsing a date/time string
Stringify the DateTime instance according to pq\DateTime::$format.
Serialize to JSON.
Details
__construct(string $datetime = 'now', null|DateTimeZone $timezone = null)
(PHP 8 >=8.3.0)
void
__wakeup()
No description
string
format(string $format)
Returns date formatted according to given format.
DateTime|false
modify(string $modifier)
Alter the timestamp of a DateTime object by incrementing or decrementing in a format accepted by strtotime().
DateTime
add(DateInterval $interval)
Adds an amount of days, months, years, hours, minutes and seconds to a DateTime object
static DateTime
createFromImmutable(DateTimeImmutable $object)
No description
DateTime
sub(DateInterval $interval)
Subtracts an amount of days, months, years, hours, minutes and seconds from a DateTime object
DateTimeZone|false
getTimezone()
Get the TimeZone associated with the DateTime
DateTime
setTimezone(DateTimeZone $timezone)
Set the TimeZone associated with the DateTime
int
getOffset()
Returns the timezone offset
DateTime
setTime(int $hour, int $minute, int $second = 0, int $microsecond = 0)
Sets the current time of the DateTime object to a different time.
DateTime
setDate(int $year, int $month, int $day)
Sets the current date of the DateTime object to a different date.
DateTime
setISODate(int $year, int $week, int $dayOfWeek = 1)
Set a date according to the ISO 8601 standard - using weeks and day offsets rather than specific dates.
DateTime
setTimestamp(int $timestamp)
Sets the date and time based on a Unix timestamp.
int
getTimestamp()
Gets the Unix timestamp.
DateInterval
diff(DateTimeInterface $targetObject, bool $absolute = false)
Returns the difference between two DateTime objects represented as a DateInterval.
static DateTime|false
createFromFormat(string $format, string $datetime, null|DateTimeZone $timezone = null)
Parse a string into a new DateTime object according to the specified format
static array|false
getLastErrors()
Returns an array of warnings and errors found while parsing a date/time string
static DateTime
__set_state(array $array)
The __set_state handler
static DateTime
createFromInterface(DateTimeInterface $object)
No description
array
__serialize()
No description
void
__unserialize(array $data)
No description
static DateTime
createFromTimestamp(int|float $timestamp)
No description
int
getMicrosecond()
No description
setMicrosecond(int $microsecond)
No description
string
__toString()
Stringify the DateTime instance according to pq\DateTime::$format.
mixed
jsonSerialize()
Serialize to JSON.
Alias of pq\DateTime::__toString().