PHP | date_timestamp_set() Function
Last Updated :
17 Sep, 2018
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:
Parameters: This function accepts two parameters as mentioned above and described below:
- $object: It is a mandatory parameter which is used to specify the DateTime object which is returned by the date_create() function.
- $unixtimestamp: This parameter is used to set the Unix timestamp representing the date.
Return Value: This function returns the DateTime object on success or False on failure.
Below programs illustrate the date_timestamp_set() function in PHP:
Program 1:
<?php
$date = date_create();
echo date_format( $date , 'U = d-m-Y H:i:s' ) . "\n" ;
date_timestamp_set( $date , 1373502124);
echo date_format( $date , 'U = d-m-Y H:i:s' );
?>
|
Output:
1537159667 = 17-09-2018 04:47:47
1373502124 = 11-07-2013 00:22:04
Program 2:
<?php
$date = new DateTime();
echo $date ->format( 'U = d-m-Y H:i:s' ) . "\n" ;
$date ->setTimestamp(1171564674);
echo $date ->format( 'U = d-m-Y H:i:s' );
?>
|
Output:
1537159667 = 17-09-2018 04:47:47
1171564674 = 15-02-2007 18:37:54
Related Articles:
Reference: http://php.net/manual/en/datetime.settimestamp.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...