我正在寻找一年中第一天的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";
>
Run Code Online (Sandbox Code Playgroud)
我知道有其他方法可以检索日期,但我搜索字符串的DateTime-> modify()没有其他解决方案.
Aur*_*osa 12
您也应该指定年份,如您在此示例中所示:
"first day of January 2008"
Run Code Online (Sandbox Code Playgroud)
来自官方文件.
更新:适用于php版本> = 5.3.6
| 归档时间: |
|
| 查看次数: |
13204 次 |
| 最近记录: |