Home >Backend Development >PHP Problem >How to convert timestamp to hours and minutes in php
How to convert timestamps into hours and minutes in php: 1. Get the UNIX system timestamp through time(); 2. Through "date("Y-m-d h:i:s", $d);" Just convert the timestamp into a time that is easy to read.
#The operating environment of this article: Windows7 system, PHP7.1, Dell G3 computer.
How to convert timestamp to hours and minutes in php?
Simple implementation of PHP timestamp and specific time conversion
Three built-in functions:
time() //获取UNIX系统时间戳 mktime(hour,minute,second,month,day,year) //将指定时间转化为时间戳 date(时间格式,时间戳) //将时间戳转化为方便阅读的时间
time -> date:
$now = time(); echo "时间戳是 " .$now; echo "创建日期是 " . date("Y-m-d h:i:s", $now);
Output:
时间戳是 1404610907 创建日期是 2014-07-06 09:41:47
mktime -> date:
$d=mktime(9, 41, 47, 7, 6, 2014); echo "时间戳是 " .$d; echo "创建日期是 " . date("Y-m-d h:i:s", $d);
Output:
时间戳是 1404610907 创建日期是 2014-07-06 09:41:47
Note:
Generally, when registering or logging in, the time function is used by default to obtain the current timestamp. When there is a business that needs to specify a specific time, the mktime function can be used to convert it to a specific time based on the specific time. Stamp, and the date function can reverse the timestamp and convert it into a specific time for easy viewing.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to convert timestamp to hours and minutes in php. For more information, please follow other related articles on the PHP Chinese website!