在 WordPress 中,你可以使用 current_time()
函数来获取当前的时间。这个函数接受两个参数:$type
和 $gmt
。
$type
参数指定你想要返回的时间的格式。可以使用的值包括 ‘mysql’、’timestamp’ 和 ‘gmt’。$gmt
参数指定是否返回 GMT 时间。如果设置为 true,则返回 GMT 时间;如果设置为 false,则返回本地时间。
例如,下面的代码将返回当前的本地时间,格式为 ‘mysql’:
$current_time = current_time( 'mysql' );
要返回当前的 GMT 时间,可以使用以下代码:
$current_time = current_time( 'mysql', true );
如果你想要使用其他的时间格式,可以使用 PHP 的 date()
函数来格式化时间。例如,下面的代码将返回当前的本地时间,格式为 ‘Y-m-d H:i:s’:
$current_time = date( 'Y-m-d H:i:s' );
作者:牛奇网,本站文章均为辛苦原创,在此严正声明,本站内容严禁采集转载,面斥不雅请好自为之,本文网址:https://www.niuqi360.com/wordpress/how-to-get-current-time-in-wordpress/