views:

90

answers:

2

I am in Albuquerque, NM. I am trying to update some stamps every time I put an entry into a database.

Here is what I use.

date_default_timezone_set("US/Mountain");
$stamp =mktime();
//$stamp = gmmktime();
$time = date("H:i:s",$stamp);$date = date("Y-m-d",$stamp);

My local time is 12:15 PM but what I get is 18:15PM instead.

If you can see what's going wrong please let me know.

A: 

Try date_default_timezone_set("America/Denver");

Scott Wilson
I don't think this would make a difference. While `America/Denver` is preferred over `US/Mountain`, the latter is still valid (for now). See http://www.php.net/manual/en/timezones.others.php
zombat
Is it possible you're using php < 5.1 and the date_default_timezone_set function doesn't exist?
Scott Wilson
@Scott: then a fatal "undefined function" would occur.
VolkerK
A: 

"My local time is 12:15 PM but what I get is 18:15PM instead."
6 hours ...that's the offset between UTC and American/Mountain, 18:00 in your local timezone is 12:00 UTC.
What does

$rc = date_default_timezone_set("US/Mountain");
$stamp =mktime();
echo 'version: ', phpversion(), "\n";
echo 'rc=', var_dump($rc);
echo 'stamp: ', $stamp, "\n";
echo 'time(): ', time(), "\n";
echo 'date: ', date(DateTime::ISO8601, $stamp), "\n";
echo 'gmdate: ', gmdate(DateTime::ISO8601, $stamp), "\n";

print?

VolkerK
version: 5.2.13rc=bool(true) stamp: 1271616283 time(): 1271616283 date: 2010-04-18T12:44:43-0600 (AHA!)gmdate: 2010-04-18T18:44:43+0000Isn't this what I try to do in essence?
seaworthy
Yes it is. And the output looks fine. So my bets right now are on "the code you've posted is not the code you've tested." ;-)
VolkerK