从时间戳添加和减去时间

问题描述:

I send a timestamp to my my database, and when I get it back it shows me the time 7 hours earlier, because of the local time at the server's location.

I don't want to modify the server time since the timestamp has to show minutes or hours ago to different users in different countries.

The solution would be to add or subtract time depending the country. Is there a way to show the time of the post to different users in different timezones correctly with a simple function?

Or can you give me something to modify the timestamp?

我将时间戳发送到我的数据库,当我收回时它会显示7小时前的时间, 因为服务器位置的本地时间。 p>

我不想修改服务器时间,因为时间戳必须在几分钟或几小时前显示给不同国家/地区的不同用户。 p>

解决方案是根据国家/地区添加或减去时间。 有没有办法通过简单的功能正确显示不同时区的不同用户的帖子时间? p>

或者你可以给我一些修改时间戳的内容吗? p> div>

As the UNIX timestamp that comes from PHP is defined as "time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)" you can just add or subtract any seconds from that and it'll be OK.

e.g. add one hour to timestamp:

$time = time() + 60*60;

equals

$time = time() + 3600;