date
函数是 PHP 中的内置函数,用于格式化当前日期和时间。
语法:
1 | string date ( string $format [, int $timestamp = time() ] ) |
参数:
format
:指定格式化字符串,可以使用特殊字符表示日期和时间的元素。timestamp
:可选参数,指定要格式化的时间戳。
例如:
1 2 | $today = date ( "Y-m-d H:i:s" ); echo "Today is $today" ; |
运行以上代码后,将得到以下输出:
1 | Today is 2023-02-10 09:48:50 |
可以看到,函数将当前日期和时间格式化为 Y-m-d H:i:s
的形式。
请注意,可以使用的格式化字符串的详细信息可以在 PHP 文档中查找:https://www.php.net/manual/en/function.date.php
发布者:彬彬笔记,转载请注明出处:https://www.binbinbiji.com/php/3032.html