Home > Backend Development > PHP Problem > How to convert timestamp to hours and minutes in php

How to convert timestamp to hours and minutes in php

藏色散人
Release: 2023-03-13 22:42:02
Original
4369 people have browsed it

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.

How to convert timestamp to hours and minutes in php

#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(时间格式,时间戳)   //将时间戳转化为方便阅读的时间
Copy after login

time -> date:

$now = time();
echo "时间戳是 " .$now;
echo "创建日期是 " . date("Y-m-d h:i:s", $now);
Copy after login

Output:

时间戳是 1404610907
创建日期是 2014-07-06 09:41:47
Copy after login
Copy after login

mktime -> date:

$d=mktime(9, 41, 47, 7, 6, 2014);
echo "时间戳是 " .$d;
echo "创建日期是 " . date("Y-m-d h:i:s", $d);
Copy after login

Output:

时间戳是 1404610907
创建日期是 2014-07-06 09:41:47
Copy after login
Copy after login

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!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template