My goal: Getting the datetime of every next sunday at 17:00:00 GMT+0/UTC time (for a countdown)

User from +0 GMT gets: 2014/01/11 17:00:00
User from +1 GMT gets: 2014/01/11 18:00:00
User from +3 GMT gets: 2014/01/11 20:00:00
etc.

I got this far:

date_default_timezone_set("UTC");
$nextsat = strtotime("next Saturday");
$saturday = date(strtotime('+17 hours', $nextsat));

Now the problem is: it's counting up 17 hours at my local time, instead of the GMT+0 Saturday time.

I tried also many other things, and nothing seems to work.

有帮助吗?

解决方案

its not working because you have to set your timezone to places

Like:

  date_default_timezone_set('America/Los_Angeles');

Here the list of all timezones:

http://php.net/manual/en/timezones.php

UPDATE:

Try this:

$nextsat = strtotime("next Saturday");
date_default_timezone_set("UTC");
$saturday = date(strtotime('+17 hours', $nextsat));

Set utc time after "next saturday"

其他提示

You should try this point of view to see if it solves your problem :

$h = "17";// Hour for time zone goes here e.g. +7 or -4, just remove the + or -
$hm = $h * 60; 
$ms = $hm * 60;
$gmdate = gmdate("m/d/Y g:i:s A", time()-($ms)); // the "-" can be switched to a plus if that's what your time zone is.
echo "Your current time now is :  $gmdate . ";
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top