我试过这段代码,它会给我正确的日期,但时间不正确:
function convert_datetime($str) {
list($date, $time) = explode(' ', $str);
list($year, $month, $day) = explode('-', $date);
list($hour, $minute) = explode(':', $time);
$timestamp = mktime($hour, $minute, $year, $month, $day);
return $timestamp;
}
if(isset($_POST['submit']))
{
$datetime=$_POST['startdate'].' '.$_POST['start_hour'].":".$_POST['start_minute'];
$timestamp=convert_datetime($datetime);
echo "DateTime:".$datetime;
echo " ";
echo "Timestamp:".$timestamp;
echo " ";
$dateandtime = date("Y-m-d H:i", $timestamp);
echo "converted:".$dateandtime;
}
有输入:2013-1-21 21:51
我会把这个拿出来
DateTime:2013-1-21 21:51 Timestamp:1358807073 converted:2013-01-21 22:24
所以顺序不正确。在时间部分我有问题。如何解决这个问题?