如何在 PHP 中获取当前日期和时间?

编程入门 行业动态 更新时间:2024-10-27 09:43:31
本文介绍了如何在 PHP 中获取当前日期和时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

哪个 PHP 函数可以返回当前日期/时间?

Which PHP function can return the current date/time?

推荐答案

// Simply: $date = date('Y-m-d H:i:s'); // Or: $date = date('Y/m/d H:i:s'); // This would return the date in the following formats respectively: $date = '2012-03-06 17:33:07'; // Or $date = '2012/03/06 17:33:07'; /** * This time is based on the default server time zone. * If you want the date in a different time zone, * say if you come from Nairobi, Kenya like I do, you can set * the time zone to Nairobi as shown below. */ date_default_timezone_set('Africa/Nairobi'); // Then call the date functions $date = date('Y-m-d H:i:s'); // Or $date = date('Y/m/d H:i:s'); // date_default_timezone_set() function is however // supported by PHP version 5.1.0 or above.

有关时区参考,请参阅支持的时区列表.

For a time-zone reference, see List of Supported Timezones.

更多推荐

如何在 PHP 中获取当前日期和时间?

本文发布于:2023-05-29 23:03:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/355007.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   时间   如何在   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!