wordpress中返回1970的当前时间函数
如何更正代码。我正在尝试获取最后一次登录时间,但它一直返回1970年1月1日凌晨12:00 这是我的密码wordpress中返回1970的当前时间函数,wordpress,Wordpress,如何更正代码。我正在尝试获取最后一次登录时间,但它一直返回1970年1月1日凌晨12:00 这是我的密码 add_action('wp_login', 'get_current_time', 0, 2); function get_current_time($login, $user) { $user = get_user_by('login',$login); $time = current_time( 'timestamp'
add_action('wp_login', 'get_current_time', 0, 2);
function get_current_time($login, $user) {
$user = get_user_by('login',$login);
$time = current_time( 'timestamp' ); or time();
update_user_meta( $user->ID, '_last_login', $time );
}
function return_current_time(){
$current_login = get_user_meta( $user->ID, '_last_login', true );
$the_currentlogin_date = date('M j, Y h:i a',$current_login);
return $the_currentlogin_date;
}
add_shortcode('lastlogin','return_current_time');
尝试改用date()函数。此示例将获取东部时区的当前日期2019年9月16日和时间6:12:15
add_action('wp_login', 'get_current_time', 0, 2);
function get_current_time($login, $user) {
$user = get_user_by('login',$login);
date_default_timezone_set("America/New_York"); // set your proper timezone
$time = date("m-d-y h:i:s");
update_user_meta( $user->ID, '_last_login', $time );
}
function return_current_time(){
$current_login = get_user_meta( $user->ID, '_last_login', true );
$the_currentlogin_date = date('M j, Y h:i a',$current_login);
return $the_currentlogin_date;
}
add_shortcode('lastlogin','return_current_time');
current_time()
和/或time()
获取服务器的时间和日期。你检查过你的服务器了吗?没有,我没有。这可能是个问题。我怎样才能让它占用我网站的时间呢?你应该问问托管公司。