English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP Date & Time Function Manual
The idate() function formats the local time and date into an integer
The idate() function accepts a format string as a parameter to format the local date in the specified format/Time, then return the date/Time
idate($format, [$timestamp])
Format the timestamp according to the given format character and return the numeric result.
timestamp is optional, the default value is the local current time, that is, the value of time(). Unlike date(), idate() only accepts a single character as the format parameter.
format character | Description |
---|---|
B | Swatch Beat/Internet Time |
d | Day of the month |
h | Hour (12 Hour format) |
H | Hour (24 Hour format) |
i | Minutes |
I | If daylight saving time is enabled, then returns 1, otherwise returns 0 |
L | If it is a leap year, then returns 1, otherwise returns 0 |
m | Month number |
s | Seconds |
t | Total number of days in the month |
U | The Unix epoch (January 1 197The number of seconds since 0 00:00:00 GMT - this is the same as time() The same as |
w | Day of the week (Sunday is 0) |
W | ISO-8601 The week number in the year, starting from Monday |
y | Year (1 or 2 digits - see below for details) |
Y | Year (4 digits) |
z | Day of the year in the year |
Z | Time zone offset in seconds |
Serial Number | Parameters and Description |
---|---|
1 | format (required) This is a string value representing the local date you need to format/Time Format |
2 | timestamp (optional) This is an integer representing the timestamp of the current local time. |
The PHP idate() function returns an integer value representing a formatted date/Time
This function was originally in PHP 5introduced in version 0 and can be used in all higher versions.
The following examples demonstrateidate()Function Usage-
<?php $format = "U"; $res = idate($format); print("Timestamp: " . $res); ?>Test to see‹/›
Output Result
Timestamp: 1589280496
The following examples call the function by passing the timestamp parameteridate()Function-
<?php $date = date_create(); $timestamp = date_timestamp_get($date); $format = "U"; $res = idate($format, $timestamp); print("Timestamp: " . $res); ?>Test to see‹/›
Output Result
Timestamp: 1589282148
Let's seeidate()Various format characters of the function and their results-
<?php print("B :".idate("B")); print("\n"); print("d :".idate("d")); print("\n"); print("h :".idate("h")); print("\n"); print("H: " . idate("H")); print("\n"); print("i :".idate("i")); print("\n"); print("I :".idate("I")); print("\n"); print("L :".idate("L")); print("\n"); print("m :".idate("m")); print("\n"); print("s :".idate("s")); print("\n"); print("t :".idate("t")); print("\n"); print("U :".idate("U")); print("\n"); print("w :".idate("w")); print("\n"); print("w:".idate("W")); print("\n"); print("y :".idate("y")); print("\n"); print("Y :".idate("Y")); print("\n"); print("z :".idate("z")); print("\n"); print("Z :".idate("Z")); print("\n"); ?>Test to see‹/›
This will produce the following output-
B :758 d :18 h :5 H: 17 i :11 I :0 L :1 m :5 s :54 t :31 U :1589821914 w :1 w:21 y :20 Y :2020 z :138 Z :0
<?php $timestamp = strtotime('1st January 2014); echo idate('y', $timestamp); echo"\n"; echo idate('t', $timestamp); ?>Test to see‹/›
This will produce the following output-
14 31