如何以正确的时区输出USER_REGISTERED时间?

时间:2018-11-11 作者:Theo

I am currently using Wordpress, and an element of user_registered returns the time of registration of the user.I have set the correct timezone, but don\'t know how to get the user_registered output to match my current time.So far, this is what I have.

  date_default_timezone_set(\'America/Los_Angeles\');


    $users = get_users();

    foreach( $users as $user ) {

        $udata = get_userdata( $user->ID );

        $registered = $udata->user_registered;

        printf( \'%s member since %s<br>\', $udata->data->display_name, date( "Y-m-d H:i:s", strtotime( $registered ) ) );
    }


echo(\'date below <br>\');
echo date(\'Y-m-d H:i:s\');

The date default timezone indeed changes the timezone (last echo)However, what I want to change is the output of user_registered. (which is the stored time).

How do I globally change the way the time is being displayed when called? In other words if I call for the date/timestamp through plugin or direct, it will always give me the output of America/Los_Angeles.

Thanks in advance. I\'m a noob. FYI the echo and printf stuff is purely for temporary display. I want to change the way user_registered is rendered when called from plugin or direct.

If javascript or jquery is an option i\'m all ears.

2 个回复
SO网友:ggedde

您可以使用以下命令从WordPress设置中获取时间偏移

get_option( \'gmt_offset\' )
所以我发现最简单的方法是:

gmdate( \'Y-m-d H:i:s\', strtotime( get_option( \'gmt_offset\' ) . \' hours\', strtotime( $udata->user_registered ) ) )

SO网友:Amir

Settings > General 第页,找到标记为Timezone. 选择与您处于同一时区的城市。

结束

相关推荐

在带有PHP的子主题中包含style.css

在里面https://codex.wordpress.org/Child_Themes 这是包含样式的最佳实践。css在子主题中,必须将下面的代码放入函数中。php的子主题,但将“父样式”替换为可以在函数中找到的父主题的参数。父主题的php。我在我的主题文件中找不到它,那里也没有多少代码。使用@import包含父主题样式表的方法不适用于我,放入文件的css不会在任何浏览器的站点上显示自己。function my_theme_enqueue_styles() { $parent_s