企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
PHP中的时间默认是0时区,我们在编程过程中,一般使用的是北京时间,也就是东八区时间,所以在文件头部已经指定时区,代码如下: date_default_timezone_set('PRC');//使用北京时间 ,这样只影响当前脚本。 //修改配置文件(不推荐使用这个方式) php.ini date.timezone = PRC 同时可以使用date_default_timezone_get()函数得到已设置的时间格式,验证是否是北京时间。 什么是UNIX时间戳? 从1970年1月1日0时0分0秒到现在所经过的秒数,1970年1月1日0时0分0秒(世纪元) //返回一个日期的时间戳,如果参数为空,则返回当前日期的时间戳 echo mktime(10,4,5,9,3,2016).'<br/>'; //返回当前日期的时间戳 echo time().'<br/>'; //将英文文本日期时间解析为 Unix 时间戳: echo strtotime('January 1 1971 00:00:00').'<br/>'; echo date('Y-m-d H:m:s',time()).'<br/>'; //返回当前本地的日期/时间的日期/时间信息: $arry = getdate(); echo '<pre>'; print_r($arry); //UNIX时间戳的毫秒数: //秒数 echo microtime(true); //秒数+毫秒数形式 echo microtime(); 备注: UTC 通用协调时间(零时区) MGT 格林威治时间 = 英国伦敦的本地时间0时区 time(),mktime(),date("U"),strtotime('now');//获取当前的时间戳 mktime('时','分','秒','月','日','年'); 设置指定时间,返回时间戳。 gmmktime('时','分','秒','月','日','年'); 设置指定时间,返回零时区的时间戳。 strtotime('now'); echo(strtotime("now") . "<br>"); echo(strtotime("15 October 1980") . "<br>"); echo(strtotime("+5 hours") . "<br>"); echo(strtotime("+1 week") . "<br>"); echo(strtotime("+1 week 3 days 7 hours 5 seconds") . "<br>"); echo(strtotime("next Monday") . "<br>"); echo(strtotime("last Sunday")); 常用函数: echo microtime(); //0.97382900 1534821377 echo microtime(true); //1534821435.8161 echo date('Y-m-d H:i:s'); //2018-08-21 11:20:03 echo date('D'); //获取星期几 echo date('Y'); //获取年份 echo date('z'); //获取今天是当年的第几天 echo gmdate('Y-m-d H:i:s') //零时间 getdate() //返回时间数组 setlocale(LC_ALL,'chs');设置显示样式(中文); echo strftime("%A"); var_dump(checkdate(2,38,2011)); //验证时间的有效性