gotch4
gotch4

Reputation: 13299

Php date() function gets wrong minutes... why?

I was working with a project in Php and I noticed that date (and time too) return wrong time. At first it seemed the wrong timezone, but later I noticed that there is not one or more hours of difference (I'm working on localhost) with system clock, but about 28 minutes... That's weird.. what could it possibly be?

Upvotes: 2

Views: 4372

Answers (2)

Mark Baker
Mark Baker

Reputation: 212522

If you're using "M" or "m" for minutes, then you're actually displaying month of year. "i" is used for minutes.

Upvotes: 36

Mike Purcell
Mike Purcell

Reputation: 19999

PHP Date() functions are based on the locale settings of the server, so I would make sure that the system current time is set correctly.

On a *nix system you can do the following:

# Check current time
$ -> date
Tue Mar  6 23:48:23 UTC 2012

If you are not using the correct timezone, you can do:

$ -> rm -f /etc/localtime

# You can use any timezone you wish, I prefer UTC
$ -> ln -sf /usr/share/zoneinfo/UTC /etc/localtime 

If you need to correct your system time:

$ -> ntpdate -b pool.ntp.org

Upvotes: 3

Related Questions