PHP时间戳和日期相互转换docWord文档下载推荐.docx

上传人:b****2 文档编号:5761321 上传时间:2023-05-05 格式:DOCX 页数:7 大小:14.94KB
下载 相关 举报
PHP时间戳和日期相互转换docWord文档下载推荐.docx_第1页
第1页 / 共7页
PHP时间戳和日期相互转换docWord文档下载推荐.docx_第2页
第2页 / 共7页
PHP时间戳和日期相互转换docWord文档下载推荐.docx_第3页
第3页 / 共7页
PHP时间戳和日期相互转换docWord文档下载推荐.docx_第4页
第4页 / 共7页
PHP时间戳和日期相互转换docWord文档下载推荐.docx_第5页
第5页 / 共7页
PHP时间戳和日期相互转换docWord文档下载推荐.docx_第6页
第6页 / 共7页
PHP时间戳和日期相互转换docWord文档下载推荐.docx_第7页
第7页 / 共7页
亲,该文档总共7页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

PHP时间戳和日期相互转换docWord文档下载推荐.docx

《PHP时间戳和日期相互转换docWord文档下载推荐.docx》由会员分享,可在线阅读,更多相关《PHP时间戳和日期相互转换docWord文档下载推荐.docx(7页珍藏版)》请在冰点文库上搜索。

PHP时间戳和日期相互转换docWord文档下载推荐.docx

2.php中获得今天零点的时间戳要获得零点的unix时间戳,可以使用

$todaytime=strtotime(“today”),

然后再使用

$todaytime)转换为日期。

时间戳转换为日期

时间戳转换函数:

i:

s"

time()),"

是转换后的日期格式,time()是获得当前时间的时间戳。

如果是date("

time()),则小时分秒一起显示;

如果是

Y-m-d"

time()),只显示年月日。

例如:

time())

转换后为:

2010-07-1818:

42:

48

Y-m-d"

2010-07-18日期转换为时间戳.

classSaonekControllerextendsController{

publicfunctionindex

Action

(){

/*

时间戳转换成日期不用说了

但是日期要转成时间戳的话就要用到

strtotime()

*/

$time=time();

//

时间戳

$nowtime=date(Y-m-dH:

s,$time);

生成带格式的日期

$oldtime=2010-11-1022:

19:

21;

$catime=strtotime($oldtime);

日期转换为时间戳

$nowtimes=date(Y-m-dH:

s,$catime);

时间戳又转回日期了

echo$nowtimes;

}

?

>

3.php中时间戳转换为日期,并按照时间显示不同的内容,如刚刚,分钟前,小时前,今天,昨天等

时间转换函数

functiontransTime($ustime){

$ytime=date("

$ustime);

$rtime=date("

n月j日H:

$htime=date("

H:

$time=time()-$ustime;

$todaytime=strtotime("

today"

);

$time1=time()-$todaytime;

if($time

$str=刚刚;

}elseif($time

$min=floor($time/60);

$str=$min.分钟前;

$str=今天.$htime;

}else{

$str=$rtime;

}

return$str;

其它的参考

使用date将当时间戳与指定时间戳转换成系统时间

(1)打印明天此时的时间戳

strtotime(”+1day“)

当前时间:

echodate(”Y-m-dH:

s”,time())

结果:

2009-01-2209:

40:

25

指定时间:

s”,strtotime(”+1day”))

2009-01-2309:

(2)打印昨天此时的

PHP

strtotime(”-1day“)

echodate(

”Y-m-dH:

s”,strtotime(”-1day”))

2009-01-2109:

(3)打印下个星期此时的时间戳

strtotime(”+1week“)

s”,strtotime(”+1week”))

2009-01-2909:

(4)打印上个星期此时的时间戳

strtotime(”-1week“)

s”,strtotime(”-1week”))

2009-01-1509:

(5)打印指定下星期几的PHP时间戳

strtotime(”nextThursday“)

s”,strtotime(”nextThursday”))

2009-01-2900:

00:

00

(6)打印指定上星期几的时间戳

strtotime(”lastThursday“)

s”,strtotime(”lastThursday”))

2009-01-1500:

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 工程科技 > 能源化工

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2