2022
我们一起努力

php中日期相关函数有哪些

php中日期相关的函数有date_create、date_diff、strtotime、microtime常见的几种

1.date_create函数

date_create函数作用:

php中date_create函数的作用是用于返回一个新的DateTime对象。

date_create函数语法:

date_create(time,timezone);

参数:

time:规定日期时间字符串。

timezone:规定time的时区。

date_create函数使用方法:

例:创建一个DateTime对象,并格式化输出

$date=date_create("2021-03-23");

echo date_format($date,"Y/m/d");

2.date_diff函数

date_diff函数作用:

php中date_diff函数的作用是用于返回两个DateTime对象间的差值。

date_diff函数语法:

date_diff(datetime1,datetime2)

date_diff函数使用方法:

例:计算时间2020-03-23至2021-03-23的差值

$date1=date_create("2020-03-23");

$date2=date_create("2021-03-23");

$diff=date_diff($date1,$date2);

3.strtotime函数

strtotime函数作用:

php中strtotime函数的作用是将字符串的日期时间解析为Unix时间戳。

strtotime函数语法:

strtotime(time,now);

strtotime函数使用方法:

echo(strtotime("next Monday") ;

echo(strtotime("last Sunday"));

4.microtime函数

microtime函数作用:

php中microtime函数的作用是返回当前Unix时间戳的微秒数。

microtime函数语法:

microtime();

microtime函数使用方法:

echo(microtime());

赞(0)
文章名称:《php中日期相关函数有哪些》
文章链接:https://www.fzvps.com/90236.html
本站文章来源于互联网,如有侵权,请联系管理删除,本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。
图片版权归属各自创作者所有,图片水印出于防止被无耻之徒盗取劳动成果的目的。

评论 抢沙发

评论前必须登录!