Home>Article>Backend Development> How to convert int to date in php

How to convert int to date in php

藏色散人
藏色散人 Original
2020-09-28 09:23:12 2172browse

php How to convert int to date: first add a time timestamp; then convert it through the "$time=date("Y-m-d",$lastTime);" method.

How to convert int to date in php

Recommended: "PHP Video Tutorial"

php converts int type to time type

This project encountered the problem of timestamp conversion

The timestamp designed in the database is in int format, so certain conversion is required

$lasTtime=time();//这个是添加一个time时间戳
这个时间戳会输出当前时间并转换成int类型:1558321414 //这个是我写这个的时候的时间戳

When extracted You can use

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

这个时间戳会变成:2019-05-20 11:03:34 //这个是我写这个的时候的时间戳

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

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

will eventually 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去比较

The above is the detailed content of How to convert int to date in php. 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