php – DateTime修改当前第一天的字符串
发布时间:2020-12-13 13:46:14 所属栏目:PHP教程 来源:网络整理
导读:我正在寻找一年中第一天的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
我正在寻找一年中第一天的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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |