DateTimeInterface::getTimestampDateTimeImmutable::getTimestampDateTime::getTimestampdate_timestamp_getGets the Unix timestamp DescriptionObject-oriented style
public int DateTimeInterface::getTimestamp()
public int DateTimeImmutable::getTimestamp()
public int DateTime::getTimestamp()
Procedural style int date_timestamp_get(DateTimeInterface
$object )Gets the Unix timestamp. ParametersThis function has no parameters. Return ValuesReturns the Unix timestamp representing the date. Errors/Exceptions
If the timestamp cannot be represented as int, a
DateRangeError is thrown. Prior to PHP
8.3.0, a ValueError is thrown. And, prior to
PHP 8.0.0, Changelog
ExamplesExample #1 DateTime::getTimestamp example Object-oriented style
Procedural style
The above examples will output something similar to: 1272509157 If you need to retrieve the timestamp with millisecond or microsecond resolution, then you can use the DateTimeInterface::format function. Example #2 Retrieving timestamp with milli and microsecond resolution Object-oriented style
The above examples will output something similar to: 1674057635586 1674057635586918 See Also
|