Latest web development tutorials

PHP idate () function

PHP Date / Time PHP Date / Time Reference Manual

Examples

Format a local time / date as an integer. Test all the different formats:

<?php
echo idate("B") . "<br>";
echo idate("d") . "<br>";
echo idate("h") . "<br>";
echo idate("H") . "<br>";
echo idate("i") . "<br>";
echo idate("I") . "<br>";
echo idate("L") . "<br>";
echo idate("m") . "<br>";
echo idate("s") . "<br>";
echo idate("t") . "<br>";
echo idate("U") . "<br>";
echo idate("w") . "<br>";
echo idate("W") . "<br>";
echo idate("y") . "<br>";
echo idate("Y") . "<br>";
echo idate("z") . "<br>";
echo idate("Z") . "<br>";
?>

Running instance »

Definition and Usage

idate () function to format the local time / date as an integer.

Note: idate () function accepts a format argument as character!

grammar

idate( format,timestamp);

参数 描述
format 必需。规定如何返回结果:
  • B - Swatch Beat/Internet Time
  • d - 一个月中的第几天
  • h - 小时(12 小时制)
  • H - 小时(24 小时制)
  • i - 分
  • I - 如果启用夏令时则返回 1,否则返回 0
  • L - 如果闰年则返回 1,否则返回 0
  • m - 月份的数字
  • s - 秒
  • t - 本月的总天数
  • U - 自 Unix 纪元(January 1 1970 00:00:00 GMT)以来经过的秒数,与 time() 作用相同
  • w - 星期中的第几天(星期天是 0)
  • W - ISO-8601 格式年份中的第几个星期,每星期从星期一开始
  • y - 年份(1 或 2 位数字)
  • Y - 年份(4 位数字)
  • z - 一年中的第几天
  • Z - 以秒为单位的时区偏移量
timestamp 可选。规定需要格式化的日期/时间的 Unix 时间戳。默认为当前时间(time())。

technical details

return value: Returns the integer given timestamp formatted using the specified format.
PHP version: 5+
Update log: PHP 5.1.0: increase E_STRICT and E_NOTICE time zone errors.


PHP Date / Time PHP Date / Time Reference Manual