How to convert Unix timestamp back to readable PHP date format?

 PHP designers often in order to calculate the time difference case, the Time , the mktime these timestamp timestamp to function, into a time timestamp seconds, when the required calculation is completed, the second value if the Unix timestamp convert a timestamp What should I do to return the readable PHP date format? In fact, it can be easily achieved by using PHP's built-in date function, and the converted unit can be accurate to the second. The following is a simple example of converting timestamp back to date for your reference.


Convert Unix timestamp back to readable PHP Date format syntax
<?php
  echo'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'; //Web page encoding declaration
  echo'The current time is represented by PHP Date:'. date ("Ymd H:i:s") .'<br>'; //The current Date time means
  echo'The current time is converted to Unix timestamp:'. time() .'<br>'; //Current Unix timestamp
 
  $NowTime=time(); echo'Unix
  timestamp is converted back to a readable PHP Date representation:'. date('Ymd H:i:s',$NowTime) ;
?>
Output result (for reference only, not the real current time)
The current time is expressed by PHP Date: 2014-10-07 07:46:25 The
current time is converted to Unix timestamp: 1412667985
Unix timestamp is converted back to a readable PHP Date: 2014-10-07 07:46:25
The echo on the first line of the example is only used to output the webpage encoding declaration, not the focus of this article. Let’s start with the echo on the second line . First, use the date function to display all the current time. This is just for illustration, and then the next line echo the time function calculated Unix timestamp time stamp, and then we write a $ nowTime the variable used to record time Unix timestamp time stamp function of the calculated number of seconds, then the last $ nowTime number of seconds into the last row of date In the function, it can be converted back to a readable PHP date representation. This technique of converting Unix timestamp to PHP date is quite common, and it is recommended to practice more.

➤What is Unix timestamp? You can get the answer from this article: PHP timestamp

Post a Comment

0 Comments