Reputation: 159
I'm setting my default time zone for my page using:
date_default_timezone_set("America/Los_Angeles");
I have to set it there, because my server doesn't allow me to alter the php.ini file or .htaccess. The problem is, when I use this:
NOW()
to send the current time to my database, it still send it as the UTC timezone.
What I'm trying to do is display comments users display from a comment box on the page, and it's showing the time for each of the comments in the wrong timezone now.
Upvotes: 0
Views: 879
Reputation: 3000
date_default_timezone_set
is a PHP function. It can only affect the behaviour of PHP.
NOW()
is a database function, and changing your timezone in PHP has no effect on it. NOW()
returns in the format YYYY-MM-DD HH:MM:SS
.
time()
is the equivalent PHP function. time()
returns simply the number of seconds since the Unix Epoch. To get output in the same format as NOW()
, use date("Y-m-d H-i-s");
. This automatically uses time()
underneath to get the current system time.
Read more:
Upvotes: 1