Display last login time

I am using this script to get the last time a user logged infunction get_last_login($user_id) {$last_login = get_user_me

I am using this script to get the last time a user logged in

function get_last_login($user_id) {
    $last_login = get_user_meta($user_id, 'last_login', true);
    echo human_time_diff($last_login) . " " . __('ago');
    }

I am calling it in author.php with

<p>Last login: <?php get_last_login($userdata->ID); ?></p>

I am trying to output like "last login X days ago" but I can't get it working.

$last_login output is

2011-05-13 18:00:06

but the final output I get is

last login 15108 days ago

I am using this script to get the last time a user logged in

function get_last_login($user_id) {
    $last_login = get_user_meta($user_id, 'last_login', true);
    echo human_time_diff($last_login) . " " . __('ago');
    }

I am calling it in author.php with

<p>Last login: <?php get_last_login($userdata->ID); ?></p>

I am trying to output like "last login X days ago" but I can't get it working.

$last_login output is

2011-05-13 18:00:06

but the final output I get is

last login 15108 days ago

Share Improve this question edited May 13, 2011 at 19:49 Andycap asked May 13, 2011 at 18:19 AndycapAndycap 5852 gold badges9 silver badges22 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

Are you formatting the mysql2date() input string as 'Y-m-d H:i:s', as specified in the Codex?

Also, why not use this same format as $date_format?

EDIT:

  1. What output do you get for $last_login?
  2. The second argument in human_time_diff() is optional. Why not just omit it? That way, if you get valid output from $last_login, you should get valid output from human_time_diff().

EDIT:

The human_time_diff() function expects a UNIX timestamp for its first argument. Try wrapping $last_login in mktime(), e.g.:

$last_login_unix = mktime( $last_login );

human_time_diff( $last_login_unix );

EDIT:

Might want to use strtotime() instead of mktime():

$last_login_unix = strtotime( $last_login );

human_time_diff( $last_login_unix );

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744791072a4593918.html

相关推荐

  • Display last login time

    I am using this script to get the last time a user logged infunction get_last_login($user_id) {$last_login = get_user_me

    10小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信