PHP | DateTimeImmutable setTimestamp() Function Last Updated : 10 Oct, 2019 Comments Improve Suggest changes Like Article Like Report The DateTimeImmutable::setTimestamp() function is an inbuilt function in PHP which is used to set the date and time based on an Unix timestamp. Syntax: DateTimeImmutable DateTimeImmutable::setTimestamp( int $unixtimestamp ) Parameters: This function accepts single parameter $unixtimestamp which is used to set the Unix timestamp representing the date. Return Values: This function returns the DateTimeImmutable object. Below programs illustrate the DateTimeImmutable::setTimestamp() function in PHP: Program 1: php <?php // PHP program to illustrate DateTimeImmutable::setTimestamp() // function // Creating a new DateTimeImmutable() object $datetimeImmutable = new DateTimeImmutable(); // Initialising a unixtimestamp $unixtimestamp = '1171564674'; // Calling the DateTimeImmutable::setTimestamp() function $a = $datetimeImmutable->setTimestamp($unixtimestamp); // Getting a new set of date and time in the // format of 'U = d-m-Y H:i:s' echo $datetimeImmutable->format('U = d-m-Y H:i:s'); ?> Output: 1570187170 = 04-10-2019 11:06:10 Program 2: php <?php // PHP program to illustrate DateTimeImmutable::setTimestamp() // function // Creating a new DateTimeImmutable() object $datetimeImmutable = new DateTimeImmutable(); // Calling the DateTimeImmutable::setTimestamp() function // with the parameter of unixtimestamp $a = $datetimeImmutable->setTimestamp(1291564453); // Getting a new set of date and time in the // format of 'U = d-m-Y H:i:s' echo $datetimeImmutable->format('U = d-m-Y H:i:s'); ?> Output: 1570187171 = 04-10-2019 11:06:11 Reference: https://www.php.net/manual/en/datetimeimmutable.settimestamp.php Comment More infoAdvertise with us Next Article PHP | DateTimeImmutable setTimestamp() Function K Kanchan_Ray Follow Improve Article Tags : Web Technologies PHP PHP-date-time PHP-function Similar Reads PHP | DateTimeImmutable setDate() Function The DateTimeImmutable::setDate() function is an inbuilt function in PHP which is used to set a new date in the created DateTimeImmutable object. Syntax: DateTimeImmutable DateTimeImmutable::setDate( int $year, int $month, int $day ) Parameters: This function accepts three parameters as mentioned abo 2 min read PHP | DateTimeImmutable::setTimezone() Function The DateTimeImmutable::setTimezone() function is an inbuilt function in PHP which is used to set the time zone for the created DateTimeImmutable object. This function returns the DateTimeImmutable object or False on failure. Syntax: DateTimeImmutable::setTimezone ( TimeZone ) Parameters: This functi 1 min read PHP | DateTimeImmutable setISODate() Function The DateTimeImmutable::setISODate() function is an inbuilt function in PHP which is used to sets the ISO (International Organization for Standardization ) date into the created DateTimeImmutable object. This function sets the date according to the ISO 8601 standard, using weeks and day offsets rathe 2 min read PHP | DateTimeImmutable::sub() Function The DateTimeImmutable::sub() function is an inbuilt function in PHP which is used to subtract a number of days, months, years, hours, minutes and seconds from a created DateTimeImmutable object. Syntax: DateTimeImmutable::sub( interval ) Parameters: This function accepts a parameter interval which i 2 min read PHP | date_timestamp_set() Function The date_timestamp_set() function is an inbuilt function in PHP which is used to sets the date and time based on an Unix timestamp. This function returns the DateTime object for method chaining or False on failure. Syntax: Procedural style: date_timestamp_set( $object, $unixtimestamp ) Object orient 2 min read Like