如何使用php格式化日期以查询Google日历Feed?

时间:2011-12-07 01:14:22

标签: php javascript date google-calendar-api

我有一个事件Feed,需要这种格式的日期。

query.setMinimumStartTime("2011-12-15");
query.setMaximumStartTime("2011-12-19");

当我从数据库中取出时<?php $startmin = $line['StartDate'];?> 它的格式为“12/15/2011”

我使用<?php $fstartmax = str_replace('/','-',$startmax);?> 将“/”更改为“ - ”,现在有12-15-2011

我怎样才能成功2011-12-15 ??

2 个答案:

答案 0 :(得分:2)

$date = new DateTime('12/15/2011');
$interval = new DateInterval('P1D');
$date->add($interval);

echo $date->format('Y-m-d');

http://fr2.php.net/manual/en/class.datetime.php&amp; http://fr2.php.net/manual/en/class.dateinterval.php了解更多信息。

答案 1 :(得分:0)

您可以使用strtotime()获取时间戳,然后使用date生成时间戳,如下所示:

echo date("Y-m-d", strtotime("12/15/2011"));