1
date_default_timezone_set('GMT');

$datetime = array(
    'year'      => date('Y', time()),
    'month'     => date('m', time()),
    'day'       => date('d', time()),
    'hour'      => date('G', time()),
    'minute'    => date('i', time()),
    'second'    => date('s', time()),
);

I use this code to separate the time and then pass different segments into a jQuery date/timepicker as needed. Everything seemed fine, but I noticed after midnight GMT it was still selecting the day from my timezone, instead of the new day. The time was still correct for GMT, just not the day. Why the discrepancy?

STEELHE4RT
  • 215
  • 3
  • 11
  • 1
    You may want to call `time()` once and store the value in a variable instead of calling it six separate times. You could also leave it out, as `date()` [defaults to using `time()` for the second parameter](http://ca2.php.net/manual/en/function.date.php). – ChrisGPT was on strike Dec 24 '13 at 18:00
  • 1
    Note: You should be able to use [`gmdate()`](http://php.net/gmdate) rather than altering the default timezone for GMT/UTC. – Jonathan Lonowski Dec 24 '13 at 18:01
  • Good to know about gmdate, and time being the default timestamp lol. Guess my code is a little redundant that way at the moment. Turns out the real problem was me not using quotes for the datepicker 'defaultDate', so it was choosing today relative to the user timezone instead of using today in GMT for default. :O – STEELHE4RT Dec 25 '13 at 05:47

1 Answers1

0

Try:

date_default_timezone_set('UTC');

Refer this link: https://stackoverflow.com/a/7587637/2190889

Community
  • 1
  • 1
KumarA
  • 1,368
  • 3
  • 18
  • 41