Wordpress显示用户注册日期为1970年


Wordpress displaying user registration date as 1970

我不知道WordPress在哪里为他们网站上的一个博主抢注册日期-http://www.redbarninc.com/author/redbarnpp/

奇怪的是,当我以管理员身份登录时,它显示了正确的日期(2012年3月)。

以下是我添加到author.php文件中以显示注册日期的代码:

<p class="blogger-since">Blogger Since <?php echo date("M Y", strtotime(get_userdata(get_current_user_id( ))->user_registered)); ?></p>

谢谢

get_current_user_id()检查当前查看页面的用户的ID(0用于已注销的用户,因此没有注册日期)。相反,检查以下查询的作者的作者元:

<?php
    global $wp_query;
    $registered = date_i18n( "M Y", strtotime( get_the_author_meta( 'user_registered', $wp_query->queried_object_id ) ) );
?>
<p class="blogger-since">Blogger Since <?php echo $registered; ?></p>

日期值存储为一个数字,表示自1970年1月1日(称为Epoch)以来的时间(以秒为单位)。

值0将转换为1970年1月1日00:00:00;值1将转换为1970年1月1日00:00:01;…等等…

函数date_i18n()将时间转换为可读格式。

date_i18n("M Y", $some_value)

因此,必须检查传递给函数的值。