PHP DateTimeImmutable setTimestamp () function

PHP

Syntax:
DateTimeImmutable DateTimeImmutable::setTimestamp (int $unixtimestamp)
Parameters:This function takes one parameter, $unixtimestamp,which is used to set the Unix timestamp representing the date.Returns: this function returns a DateTimeImmutable object.The following programs illustrate the DateTimeImmutable::setTimestamp() function in PHP:Program 1:
// PHP illustration program DateTimeImmutable::setTimestamp()
// function 
// Create a new DateTimeImmutable() $dateti meImmutable = new DateTimeImmutable();  
// Initialize unixtime label $unixtimestamp = `1171564674` ;  
// Calling the DateTimeImmutable::setTimestamp() function $a = $datetimeImmutable -> setTimestamp ( $unixtimestamp );  
// Get a new set of date and time in
// format ` U = dmY H: i: s ` echo $datetimeImmutable -> format ( `U = dmY H: i: s` ); ?>
Exit:
1570187170 = 04 -10-2019 11:06:10
Program 2:
// PHP illustration program DateTimeImmutable::setTimestamp()
// function 
// Create a new DateTimeImmutable() $datetimeImmutable = new DateTimeImmutable();  
// Calling the DateTimeImmutable::setTimestamp() function
// with unixtimestamp parameter $a = $datetimeImmutable -> setTimestamp (1291564453);  
// Get a new set of date and time in
// format ` U = dmY H: i: s ` echo $datetimeImmutable -> format ( `U = dmY H: i: s` ); ?>
Exit:
1570187171 = 04 -10-2019 11:06:11
Link: https : //www.php.net/manual/en/datetimeimmutable.settimestamp.php



Get Solution for free from DataCamp guru