我想使用$ _GET []和getdate()将日期作为查询字符串拉入,形式为:YYYY-mm-dd。如果未输入日期,则获取当前日期。这就是我所做的,但我不知道我是否接近。
if(!isset($_GET['date']))
{
//$date = "2012-09-15";
$date = date('Y-m-d');
}
elseif(DateTime::createFromFormat('Y-m-d', $_GET['date']))
{
//$date = DateTime::createFromFormat('Y-m-d',$_GET['date']);
$date = $_GET['date'];
}
else
{
$date = date('Y-m-d');
}
$calendar = DateTime::createFromFormat('Y-m-d', $date);
//This is something else I was attempting
//if(isset($_GET['date']) ? $_GET['date'] : $date = date('Y-m-d')
//$date = explode("-", $_GET['date']);
//$date = date('Y-m-d');
// Create new DateTime object passing the date as a string.
$calendar = DateTime::createFromFormat('Y-m-d', $date);
答案 0 :(得分:0)
不确定你的目标是什么,但PHP的日期格式将是这样的
int strtotime ( string $time [, int $now = time() ] )