DateTime::setTimestamp

date_timestamp_set

Sets the date and time based on an Unix timestamp

Description

Object-oriented style

public DateTime DateTime::setTimestamp(int $timestamp)

Procedural style

DateTime date_timestamp_set(DateTime $object, int $timestamp)

Sets the date and time based on an Unix timestamp.

Like DateTimeImmutable::setTimestamp but works with DateTime.

The procedural version takes the DateTime object as its first argument.

Parameters

object

Procedural style only: A DateTime object returned by date_create. The function modifies this object.

timestamp

Unix timestamp representing the date. Setting timestamps outside the range of int is possible by using DateTimeImmutable::modify with the @ format.

Return Values

Returns the modified DateTime object for method chaining.

See Also

  • DateTimeImmutable::setTimestamp