Home  >  Article  >  Backend Development  >  How to transfer time in php int

How to transfer time in php int

藏色散人
藏色散人Original
2021-10-20 09:39:312794browse

php How to convert int to time: 1. Add a time timestamp; 2. Convert the int type number into time format through the "date("Y-m-d",$lastTime);" method.

How to transfer time in php int

The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer

How to transfer time with php int?

php converts int type into time type

I encountered the problem of timestamp conversion during this project

Time of database design The stamp is in int format and requires certain conversion

$lasTtime=time();//这个是添加一个time时间戳

This timestamp will output the current time and convert it to int type: 1558321414 //This is the timestamp when I wrote this

When extracted, you can use

$time=date("Y-m-d",$lastTime);//date是按你指定格式转换的函数

This timestamp will become: 2019-05-20 11:03:34 //This is the timestamp when I wrote this

 If you still want to convert 2019-05-20 11:03:34 into int format

$lastTime=strtotime($time);//$time是你要转换的变量

 It will finally become: 1558321414 //This is the timestamp when I wrote this

If there is a time difference, you can use date_default_timezone_set("PRC"); to solve the 8-hour time difference problem

'Y-m-d H:i:s'//这个是定义的时间格式
//需要什么取什么
//秒是s,分钟是i,小时是H,天是d,月是m,年是Y
$time_str = 1313994356;
echo date('i',$time_str);//要与当前时间去计算的话不用转为时间型
$c_time = time()-$time_str;//$c_time得到的就是秒,分钟的话除以60,$c_time/60

Recommended learning: "PHP video tutorial

The above is the detailed content of How to transfer time in php int. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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