Reputation: 1
I'm having a seemingly simple problem with setting the default timezone in PHP. I'm trying to use default_timezone_set()
to affect my mktime()
function unsuccessfully.
In short, my server is set to UTC and I'm setting the timezone using default_timezone_set()
, then calling mktime()
to set a database date-time stamp.
However, the time in milliseconds that returns, comes back as UTC time. I echoed out the default_timezone_get()
and it does indeed return as the timezone I'm setting and can't seem to determine why once I've successfully set the timezone that it fails to affect the mktime()
function.
Am I missing something here? Isn't setting the default timezone supposed to affect all the date/time functions in PHP?
Upvotes: 0
Views: 383
Reputation: 1
Well dumb me here, I just realized that I wasn't calling the timezone set from a third PHP file and of course, the date_default_timezone_set() function couldn't affect the separate file.
However, the answers and comments gave me some new ideas on how to handle it! Thank you all for the input.
Upvotes: 0
Reputation: 31654
Have you tried using date_default_timezone_set? From the mktime manual
<?php
// Set the default timezone to use. Available as of PHP 5.1
date_default_timezone_set('UTC');
// Prints: July 1, 2000 is on a Saturday
echo "July 1, 2000 is on a " . date("l", mktime(0, 0, 0, 7, 1, 2000));
// Prints something like: 2006-04-05T01:02:03+00:00
echo date('c', mktime(1, 2, 3, 4, 5, 2006));
?>
Upvotes: 0
Reputation: 219864
Unix timestamps are always in UTC, You need to convert it to the the proper timezone after you get the timestamp.
Upvotes: 2