我正在使用 php 的形式来捕获日期,将其转换为 unixtime,然后将其插入 mysql。问题是,当我尝试插入 2012 年 1 月 1 日时,插入的是 2011 年 12 月 31 日。这一定是一个简单的问题,但我可以使用一些帮助。
这是我的表单代码:
<select name="mo">
<?php
$arrMo = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
foreach ($arrMo as $key => $value) {
$option_val = intval($key) + 1;
echo "<option value='" . $option_val . "'>" . $value . "</option>";
}
?>
</select> /
<select name="day">
<?php
for ($b = 1; $b < 32; $b++) {
echo "<option value='" . $b . "'>" . $b . "</option>\n";
}
?>
</select> /
<select name="year">
<?php $thisyear = date("Y");
$thisyear = intval($thisyear);
for ($c = 0; $c < 6; $c++) {
$newval = $thisyear - intval($c);
echo "<option value='" . $newval . "'>" . $newval . "</option>\n";
}
?>
</select>
然后我在php中改变它:
$timestamp = $_POST['year'] . "-" . $_POST['mo'] . "-" . $_POST['day'];
$timestamp = strtotime("Y-m-d H:i:s", $timestamp);//turn it into Unix time
$mysqldatetime = date("Y-m-d H:i:s", $timestamp);
然后我尝试将其插入数据库:
$q_location = "Insert into markers(MarkerID, lat, lng, street, neighborhood, date) values(" . $nextLocation . ", '" . $_POST['latitude'] . "', '" . $_POST['longitude'] . "', '" . addslashes($_POST['address_public']) . "', '" . addslashes($_POST['neighborhood']) . "', FROM_UNIXTIME(" . $mysqldatetime . "))";
知道我做错了什么吗?