首页 > 作文

PHP时间相关常用函数用法示例

更新时间:2023-04-08 17:49:28 阅读: 评论:0

本文实例讲述了php时间相关常用函数用法。分享给大家供大家参考,具体如下:

<?php/** * 设置时区 */date_default_timezone_t("asia/shanghai"); /** * 获取时区 */echo date_default_timezone_get();//结果 utcecho "<br/>"; /** * 添加时间 */$date=date_create("2013-03-15"); //创建一个datetime 对象date_add($date,date_interval_create_from_date_string("40 month"));//years days//date_in共创未来terval_create_from_date_string 从字符串的相关部分建立一个dateinterval。echo date_format($date,"y-m-d");//结果2016-07-15echo "<br/>"; /** * 减去时间 */$date=date_create("2013-03-15");date_sub($date,date_interval_create_from_date_string("40 days"));echo date_format($date,"y-m-d");//2013-02-03echo "<br/>"; /** * 获取两个时区的差值 */$date1=date_create("2013-03-15");$date2=date_create("2013-12-12");$diff=date_diff($date1,$date2);//返回的是一个dateinterval对象echo "<pre>";var_dump($diff);// object(dateinterval)#4 (15) {//  ["y"]=>//  int(0)//  ["m"]=>//  int(8)//  ["d"]=>//  int(27)//  ["h"]=>//  int(0)//  ["i"]=>//  int(0)//  ["s"]=>//  int(0)//  ["weekday"]=>//  int(0)//  ["weekday_behavior"]=>//  int(0)//  ["first_last_day_of"]=>//  int(0)//  ["invert"]=>//  int(0)//  ["days"]=>//  int(272)//  ["special_type"]=>//  int(0)//  ["special_amount"]=>//  int(0)//  ["have_weekday_relative"]=>//  int(0)//  ["have_special_relative"]=>//  int(0)// }echo "<b钟瑞r/>"; /** * 获取当前时间戳 */$date=date_create();echo date_timestamp_get($date) .'<br/>'; $time = time();echo $time .'<br>'; echo strtotime("now") .'<br/>'; /* *获取今天0点时间戳 */ echo strtotime("today").'<br>';/** * 获取带微秒的时间 */echo microtime(true); /* *获取指定时间戳  * mktime(hour,minute,cond,month,day,year); */echo "<br/>";echo mktime(18,30,15,3,15,2019); /* *获取前一天0点时间戳 */echo "<br/>";echo strtotime('yesterday'); /* *获取昨天此时的时间戳 */echo "<br/>"; echo strtotime('-1 days'); ?>

运行结果:

asia/shanghai
2016-07-15
2013-02-03

ob长春花花语ject(dateinterval)#4 (15) {
[“y”]=>
int(0)
[“m”]=>
int(8)
[“d”]=>
int(27)
[“h”]=>
int(0)
[“i”]=>
int(0)
[“s”]=>
int(0)
[“wee上海海洋大学是几本kday”]=>
int(0)
[“weekday_behavior”]=>
int(0)
[“first_last_day_of”]=>
int(0)
[“invert”]=>
int(0)
[“days”]=>
int(272)
[“special_type”]=>
int(0)
[“special_amount”]=>
int(0)
[“have_weekday_relative”]=>
int(0)
[“have_s儿童歌谣pecial_relative”]=>
int(0)
}
1591150859
1591150859
1591150859
1591113600
1591150859.0074
1552645815
1591027200
1591064459

ps:这里再为大家推荐几款时间及日期相关工具供大家参考:

在线日期/天数计算器:

在线日期计算器/相差天数计算器:

在线日期天数差计算器:

unix时间戳(timestamp)转换工具:

本文发布于:2023-04-08 17:49:26,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/e31e02410992ad7f68b9517aa435390d.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:PHP时间相关常用函数用法示例.doc

本文 PDF 下载地址:PHP时间相关常用函数用法示例.pdf

标签:时间   在线   计算器   天数
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图