I'm working on a PHP project that uses timestamps in a lot of places. I'm having some trouble with the conversions between dates/times and UNIX timestamps, though, and I'm not sure where my problem lies.
Here is an example of some of the code I'm using (this is a converter I built to help myself out and to test my conversions):
PHP Code:
<?php
extract($_POST);
if($submit == "->") {
$timestamp = strtotime($date);
}
elseif($submit == "<-") {
$date = date("m/d/Y \a\\t G:i:s", $timestamp);
}
echo "
<form name='convert' method='POST' action='timestamp.php'>
<table style='background-color:#000069;font-size:10px;'>
<tr>
<td>Enter a date string:</td>
<td><input type='text' name='date'";
if(isset($date)) {
echo " value='$date'";
}
echo " /></td>
<td>
<input type='submit' name='submit' value='->' />
</td>
<td>
<input type='submit' name='submit' value='<-' />
</td>
<td>Or Enter a timestamp:</td>
<td><input type='text' name='timestamp'";
if(isset($timestamp)) {
echo " value='$timestamp'";
}
echo " /></td>
</tr>
</table>";
?>
The problem is, when I type in a date/time, and convert it to a timestamp, I get what looks like a valid timestamp. However, if I convert that same timestamp back to a date/time, then I lose three hours somewhere.
Example:
Let's say I type:
Code:
02/14/2006 at 23:59:00
into the first box. Then, I convert that into a timestamp. I get the result "1139968740".
If I then convert that timestamp back into a date/time string, I get:
Code:
02/14/2006 at 20:59:00
I'm assuming it has something to do with the fact that I am not specifying a timezone when I convert these things, but I'm not sure how to correct this problem.
Any thoughts?