PHP 的 strtotime() 函數可以處理閏年問題。strtotime() 函數會將任何英文文本日期時間描述解析為 Unix 時間戳,或者轉換為指定格式的時間字符串。在解析日期時,strtotime() 會自動考慮閏年情況。
例如:
echo strtotime("next Thursday"); // 輸出下一個星期四的日期,自動考慮閏年
如果你指定一個具體的日期,strtotime() 也會正確處理閏年:
echo strtotime("2022-02-29"); // 輸出 2022 年 2 月 29 日,因為 2022 年不是閏年
echo strtotime("2024-02-29"); // 輸出 2024 年 2 月 29 日,因為 2024 年是閏年
總之,strtotime() 函數可以正確處理閏年問題。