PHP中日期相关的函数有date_create、date_diff、strtotime、microtime常见的几种date_create函数date_create函数作用:php中date_create函数的作用是用于返回一个新的Date
PHP中日期相关的函数有date_create、date_diff、strtotime、microtime常见的几种
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");
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);
strtotime函数
strtotime函数作用:
php中strtotime函数的作用是将字符串的日期时间解析为Unix时间戳。
strtotime函数语法:
strtotime(time,now);
strtotime函数使用方法:
echo(strtotime("next Monday") ;
echo(strtotime("last Sunday"));
microtime函数
microtime函数作用:
php中microtime函数的作用是返回当前Unix时间戳的微秒数。
microtime函数语法:
microtime();
microtime函数使用方法:
echo(microtime());
--结束END--
本文标题: php中日期相关函数有哪些
本文链接: https://www.lsjlt.com/news/111842.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0