get_the_time()获取当前文章/页面的发布时间

目录

描述

Returns the time of the current post for use in PHP. It does not display the time. To display the time of a post, use the_time(). This tag must be used within The Loop.

get_the_time() 描述

用法

 <?php get_the_time$format$post ); ?> 

get_the_time() 用法

参数

format

(string) (可选) The format used to display the time (and date). See Formatting Date and Time for other time and date formats. WordPress is written in the programming language PHP. The date formatting functions in WordPress use PHP's built-in date formatting functions.

默认值: Time Format configured in Administration > Settings > General

post

(integer/object) (可选) post ID or object.

默认值: null. global $post object

get_the_time() 参数

返回值

(string) 

Returns the time according to the default or specified time format.

get_the_time() 返回值

示例

Default Usage

Returns the time of the current post using the WordPress default format, and displays it using the PHP echo command.

Returns the time of the post with ID $post->ID in the WordPress default format.

Getting Unix Timestamp

Assigns the local time of the current post in seconds (since January 1 1970, known as the Unix Epoch) to the variable $u_time.

In most cases, you would probably want the epoch time for GMT (rather than for the local time zone), which you can get with the get_post_time() function, setting the $gmt option to true:

get_the_time() 示例

源文件

get_the_time() 函数的代码位于 wp-includes/general-template.php

get_the_time() 源文件

相关