php timezone搞乱javascript时间

时间:2021-09-09 21:31:13

I'm using the TimeAgo plugin to update the time of posts automatically. It makes time like 05-08-2014 15:02:39 to 5 minutes ago.

我正在使用TimeAgo插件自动更新帖子的时间。它的时间像05-08-2014 15:02:39到5分钟前。

The problem is, the javascript uses client's clock for time. I'm from Bangladesh, Asia. But in php the default timezone varies from server to server. I'm outputting the format 05-08-2014 15:02:39 in PHP to convert it into something like 5 mintues ago using the TimeAgo plugin.

问题是,javascript使用客户端的时钟。我来自孟加拉国,亚洲。但在php中,默认时区因服务器而异。我在PHP中输出格式05-08-2014 15:02:39,使用TimeAgo插件将其转换为5分钟前的内容。

Because server's timezone is different, instead of showing less than a minute ago on a recent post, it shows nn hours ago. If the server is american, it shows 11 hours ago, if it's indian, the time shows 30 minutes ago. How do I fix it?

因为服务器的时区不同,而不是在最近的帖子上显示不到一分钟,它在nn小时前显示。如果服务器是美国的,它显示11小时前,如果它是印度的,时间显示30分钟前。我如何解决它?

1 个解决方案

#1


0  

As stated on the TimeAgo project page:

如TimeAgo项目页面所述:

Are you concerned about time zone support? Don't be. Timeago handles this too. As long as your timestamps are in ISO 8601 format and include a full time zone designator (±hhmm), everything should work out of the box regardless of the time zone that your visitors live in.

您是否关注时区支持?不要。 Timeago也处理这个问题。只要您的时间戳采用ISO 8601格式并包含全时区指示符(±hhmm),无论访问者居住的时区如何,一切都应该开箱即用。

So echo the dates server side with date('c',$timestamp) and everything should work fine.

所以使用日期('c',$ timestamp)回显日期服务器端,一切都应该正常工作。

#1


0  

As stated on the TimeAgo project page:

如TimeAgo项目页面所述:

Are you concerned about time zone support? Don't be. Timeago handles this too. As long as your timestamps are in ISO 8601 format and include a full time zone designator (±hhmm), everything should work out of the box regardless of the time zone that your visitors live in.

您是否关注时区支持?不要。 Timeago也处理这个问题。只要您的时间戳采用ISO 8601格式并包含全时区指示符(±hhmm),无论访问者居住的时区如何,一切都应该开箱即用。

So echo the dates server side with date('c',$timestamp) and everything should work fine.

所以使用日期('c',$ timestamp)回显日期服务器端,一切都应该正常工作。