在PHP中,获取今年第一天的日期可以通过多种方式实现。以下是一些常用的方法:
date()
和 strtotime()
$firstDayOfYear = date('Y-m-d', strtotime('first day of January this year'));
echo $firstDayOfYear; // 输出格式为:2023-01-01
DateTime
类$datetime = new DateTime('first day of January this year');
echo $datetime->format('Y-m-d'); // 输出格式为:2023-01-01
$year = date('Y');
$firstDayOfYear = $year . '-01-01';
echo $firstDayOfYear; // 输出格式为:2023-01-01
date()
函数:用于格式化本地时间/日期。strtotime()
函数:将任何英文文本的日期时间描述解析为 Unix 时间戳。DateTime
类:提供了面向对象的日期和时间处理方式。通过以上方法,你可以轻松地在PHP中获取今年的第一天,并应用于各种实际场景中。
TAIC
136届广交会企业系列专题培训
云+社区沙龙online第5期[架构演进]
云+社区技术沙龙[第10期]
腾讯自动驾驶系列公开课
TVP「再定义领导力」技术管理会议
2024清华公管公益直播讲堂——数字化与现代化
领取专属 10元无门槛券
手把手带您无忧上云