这两个函数都返回日期和时间。他们之间有什么区别?你有什么例子吗?谢谢
获取时间和获取日期有什么不同?
2 个回复
SO网友:Rarst
它们非常相似,但有一些细微差别:
function get_the_date( $d = \'\' ) {
global $post;
$the_date = \'\';
if ( \'\' == $d )
$the_date .= mysql2date(get_option(\'date_format\'), $post->post_date);
else
$the_date .= mysql2date($d, $post->post_date);
return apply_filters(\'get_the_date\', $the_date, $d);
}
function get_the_time( $d = \'\', $post = null ) {
$post = get_post($post);
if ( \'\' == $d )
$the_time = get_post_time(get_option(\'time_format\'), false, $post, true);
else
$the_time = get_post_time($d, false, $post, true);
return apply_filters(\'get_the_time\', $the_time, $d, $post);
}
get_the_date()
始终适用于当前全局$post
,get_the_time()
允许您将post指定为参数。它们默认为不同的格式,存储在
date_format
和time_format
选项。它们将输出通过不同的滤波器
get_the_date
和get_the_time
加上较低级别get_post_time
分别地
SO网友:Chip Bennett
这个the_date()
模板标签每次只输出一次发布日期;因此,如果两个或多个帖子具有相同的发布日期,则该日期仅在循环中第一次出现时输出。这个the_time()
模板标记按照正常方式输出发布时间(使用任何有效的日期/时间字符串)。
这个get_the_date()
和get_the_time()
然而,模板标记本质上是相同的。它们用于返回the_date()
和the_time()
. As per the Codex:
不像the_date()
此标签将always return 日期。使用“get\\u the\\u date”筛选器修改输出。
所以,区别不在于get_the_*()
模板标记本身,但在the_*()
使用它们的模板标记。
结束