0

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 Answers 2

0

You can get the time offset from WordPress Settings using

get_option( 'gmt_offset' )

So I found the easiest method is to do this:

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

On the Settings > General page, find the section labeled Timezone. Select a city in the same timezone as you.

1
  • This does not work for the User Table. The user_registered is always stored as UTC Time regardless of the Settings > General Timezone. You will need to convert the time yourself.
    – ggedde
    Aug 25, 2021 at 4:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.