I ran time() at 6:38:47 and it returned a different value than strtotime of the same time. Why is this?
It should absolutely return the same value. Run this code:
<?php
$time = time();
$string = date('Y-m-d H:i:s', $time);
$strtotime = strtotime($string);
print "time = $time
";
print "string = $string
";
print "strtotime = $strtotime
";
print "difference = ".($time-$strtotime)."
";
?>
My output right now:
time = 1377686839
string = 2013-08-28 12:47:19
strtotime = 1377686839
difference = 0
Are you getting a difference with this? You could also post your test code, maybe there's a mistake in there.
strtotime
interprets the time string argument according to the system timezone; time
is timezone-independent because it just returns the number of seconds since the start of the Unix epoch.
If your system timezone is anything other than UTC you should expect the values to differ, since the time string argument you passed to strtotime
was hardcoded. Your notion of "current wall clock time" and that of the system are different, hence the difference in the timestamps.