当您
1970-01-01从那里回来时
date(),意味着时间戳不正确。该日期是UNIX时代。
当涉及到Javascript(在这种情况下为日期选择器)时,您应始终确保获得的实际上是您期望的结果。简单地将其传递
strtotime()将导致类似您在此处遇到的问题。
处理日期的一种好方法是使用
datetime扩展名。它有一个静态方法,
DateTime::createFromFormat可让您使用任何格式解析任何日期:
// The value from the datepicker$dpValue = '12/30/2013';// Parse a date using a user-defined format$date = DateTime::createFromFormat('d/m/Y', $dpValue);// If the above returns false then the date// is not formatted correctlyif ($date === false) { header('HTTP/1.0 400 Bad Request'); die('Invalid date from datepicker!')}// Using the parsed date we can create a// new one with a formatting of out choosing$forSQL = $date->format('Y-m-d');// ...


