PHP date_interval_format() 函式
示例
計算兩個日期之間的間隔,然後格式化該間隔
<?php
$date1=date_create("2013-01-01");
$date2=date_create("2013-02-10");
$diff=date_diff($date1,$date2);
// %a 輸出總天數
echo $diff->format("總天數: %a.");
?>
自己動手試一試 »
定義和用法
date_interval_format() 函式是 DateInterval::format() 的別名。
DateInterval::format() 函式用於格式化間隔。
語法
DateInterval::format(format)
引數值
引數 | 描述 |
---|---|
format | 必需。指定格式。以下字元可用於format引數字串
注意:每個格式字元都必須以 % 符號為字首! |
技術詳情
返回值 | 返回格式化後的間隔 |
---|---|
PHP 版本 | 5.3+ |
PHP 更新日誌 | PHP 7.1:添加了F和f引數 |
❮ PHP 日期/時間參考