1

My date is ahead 1 hour when I post to mySQL via php. I'm in Los Angeles. How can i make the time correct?

Here is what I currently have:

$date = date("m/d/y g:i A") ; 
Erik
  • 5,701
  • 27
  • 70
  • 119
  • 2
    `I'm in Los Angeles` - that's your problem right there! (Just kidding. It's likely a time zone issue. Where is your server located?) – Pekka Sep 25 '11 at 21:18
  • Good question. In Colorado, which is central time zone... there one hour ahead – Erik Sep 25 '11 at 21:21
  • Is it possible to get the time from the users computer? – Erik Sep 25 '11 at 21:22
  • not easily, no. Here's a good answer to that: [How do I show datetime in the same time zone as user using PHP or javascript?](http://stackoverflow.com/q/2934465) – Pekka Sep 25 '11 at 21:23

4 Answers4

0

It depends on your specific case, but I had saved the date as UTC / GMT time, so I had to use the gmdate function instead of date. E.g.

gmdate("H:i",$time)

Sbhklr
  • 2,693
  • 1
  • 17
  • 20
0

see

date_default_timezone_set

like

date_default_timezone_set('America/Los_Angeles');
Rusty Fausak
  • 7,355
  • 1
  • 27
  • 38
0

First check if servers time is correct ( on linux use date shell command). If yes, you just set the time and you're good.

If not you have to change it in php with setlocale() or date_default_timezone_set() function

Tadej Magajna
  • 2,765
  • 1
  • 25
  • 41
0

Use this to get the time zone PHP is using date_default_timezone_get();

If you're in Los Angeles you can set your time zone temporarily for only the current script date_default_timezone_set('America/Los_Angeles');

http://php.net/manual/en/function.date-default-timezone-set.php

Also pass T in the date function:

echo date("D M j G:i:s T Y"); outputs Mon May 25 16:23:49 EDT 2009

Mob
  • 10,958
  • 6
  • 41
  • 58