Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

文章页的最近评论小工具中评论发布时间的相对时间永远是刚刚 #517

Merged
merged 1 commit into from
Jun 20, 2022

Conversation

n0099
Copy link
Contributor

@n0099 n0099 commented Jun 8, 2022

function timeago($time)
添加以下log会发现不同页面有着不同的php默认时区设置,原因未知
image

首页:
image

文章页:
image

由于默认时区不同所以给此strtotime()传入非utc时区的字符串形式日期时间(形如2022-06-08 17:00:00的mysql datetime格式)会导致$dtime变量值为负数从而对所有评论的发布时间求相对时间结果都为刚刚

$time = strtotime($time);

另外删除了sql中AND (wp_posts表.)user_id != '1'where条件,uid 1一般都是站长用户

@seatonjiang
Copy link
Owner

这个情况应该是PHP时区和WP时区不一致造成的,因为前面把date换成了wp_date

@seatonjiang seatonjiang merged commit dc88428 into seatonjiang:main Jun 20, 2022
@n0099
Copy link
Contributor Author

n0099 commented Jun 23, 2022

我的评价是多用utc时间

@n0099
Copy link
Contributor Author

n0099 commented Oct 18, 2022

不同页面有着不同的php默认时区设置,原因未知

3704666#diff-a022f50ce4fe2c91b4c45ef52f5fcf78e88255b5e067817510f2b1b697c78752L80
https://make.wordpress.org/core/2019/09/23/date-time-improvements-wp-5-3/

don’t change PHP time zone with date_default_timezone_set() (this one is hard requirement for correct core operation!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants