我正在寻找一年中第一天的DateTime修改字符串(现在是2011年1月1日).我尝试了以下方法:
<?PHP $time = new DateTime(); // works as expected,the first day of the current month $time->modify('first day of this month'); echo $time->format('c')."\n"; // this doesn't work. I also tried several other ways $time->modify('first day of january'); echo $time->format('c')."\n"; >
我知道有其他方法可以检索日期,但我搜索字符串的DateTime-> modify()没有其他解决方案.
您也应该指定年份,如您在此示例中所示:
"first day of January 2008"
从official doc.
更新:适用于PHP版本> = 5.3.6