php method to convert int to date: 1. Add a time timestamp through "$lasTtime=time();"; 2. Use the "date("Y-m-d",$lastTime);" method to convert to date Just format.
The operating environment of this article: Windows7 system, PHP7.1 version, Dell G3 computer
How to transfer date using 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 all 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 echo date('i',$time_str); //要与当前时间去计算的话不用转为时间型 $time_str = 1313994356; c_time = time()-$time_str; c_time得到的就是秒 //分钟的话除以60 c_time/60跟5去比较
Recommended study: "PHP Video Tutorial"
The above is the detailed content of How to convert date in php int. For more information, please follow other related articles on the PHP Chinese website!