English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
These functions allow you to obtain the date and time from the server running the PHP script. You can use these functions to format dates and times in many different ways.
These functions can be used without installation. They are part of the PHP core.
Date/Time configuration options:
Name | Default | Description | Variable |
---|---|---|---|
date.default_latitude | "" 31.7667"" | Specify default latitude (used by date_sunrise() and date_sunset()) | PHP_INI_ALL |
date.default_longitude | "" 35.2333"" | Specify default longitude (used by date_sunrise() and date_sunset()) | PHP_INI_ALL |
date.sunrise_zenith | "" 90.83"" | Specify default sunrise zenith (used by date_sunrise() and date_sunset()) | PHP_INI_ALL |
date.sunset_zenith | "" 90.83"" | Specify default sunset zenith (used by date_sunrise() and date_sunset()) | PHP_INI_ALL |
date.timezone | "" | Specify default timezone | PHP_INI_ALL |
Version-Indicates the earliest PHP version that supports this function.
Number | Function name | Function description | Version |
---|---|---|---|
1 | checkdate() | Validate Gregorian date | 3 |
2 | date_create() | Return a new DateTime object | 5 |
3 | date_date_set() | Set a new date. | 5 |
4 | date_default_timezone_get() | Return the default timezone, used by all Date/Time function usage. | 5 |
5 | date_default_timezone_set() | Set default timezone, used by all Date/Time function usage. | 5 |
6 | date_format() | Return a date formatted according to the given format | 5 |
7 | date_isodate_set() | Set ISO date | 5 |
8 | date_modify() | Modify timestamp | 5 |
9 | date_offset_get() | Return the daylight saving time offset | 5 |
10 | date_parse() | Return an associative array with detailed information for the given date | 5 |
11 | date_sun_info() | Return an array containing information about the sunrise on the specified date and location/Dusk and dusk start/An array of information about the end of dusk. | 5 |
12 | date_sunrise() | Return the given date/The sunrise time of the location | 5 |
13 | date_sunset() | Return the given date/The sunset time of the location | 5 |
14 | date_time_set() | Set time | 5 |
15 | date_timezone_get() | Return the timezone of the given DateTime object. | 5 |
16 | date_timezone_set() | Set the timezone of the DateTime object | 5 |
17 | date() | Format local date and time | 3 |
18 | getdate() | Return an array containing date and time information of the Unix timestamp | 3 |
19 | gettimeofday() | Return an array containing information about the current time | 3 |
20 | gmdate() | Format GMT/UTC date/Time | 3 |
21 | gmmktime() | Return the Unix timestamp of the GMT date | 3 |
22 | gmstrftime() | Format GMT according to the language environment/UTC time/Date | 3 |
23 | idate() | Convert local time/Format date as an integer | 5 |
24 | localtime() | Return local time. | 4 |
25 | microtime() | Return the microseconds of the current Unix timestamp | 3 |
26 | mktime() | Return the Unix timestamp of a date | 3 |
27 | strftime() | Format local time according to the locale/Date | 3 |
28 | strptime() | Parse the time generated by strftime()/Date | 5 |
29 | strtotime() | Parse any English text description of a date or time into a Unix timestamp | 3 |
30 | time() | Return the Unix timestamp of the current time | 3 |
31 | timezone_abbreviations_list() | Return an associative array containing daylight saving time, offset, and timezone name | 5 |
32 | timezone_identifiers_list() | Return an array of numeric indices with all timezone identifiers | 5 |
33 | timezone_name_from_abbr() | Return the timezone name from abbreviation | 5 |
34 | timezone_name_get() | Return the name of the timezone | 5 |
35 | timezone_offset_get() | Return the timezone offset from Greenwich Mean Time | 5 |
36 | timezone_open() | Return a new DateTimeZone object | 5 |
37 | timezone_transitions_get() | Return all timezone conversions when returning | 5 |
38 | date_add() | Adds days, months, years, hours, minutes, and seconds to a date | 5.3 |
39 | date_create_from_format() | Creates a date by parsing a time string according to the specified format | 5.3 |
40 | date_diff() | Calculates and returns the difference between two dates | 5.3 |
41 | date_parse_from_format() | Returns information about a given date according to the specified format | 5.3 |
42 | date_parse() | Returns an associative array with detailed information about a specified date | 5.2 |
43 | date_sub() | Subtracts days, months, years, hours, minutes, and seconds from a specified date | 5.3 |
44 | date_timestamp_get() | Returns Unix timestamp | 5.3 |
45 | date_timestamp_set() | Sets date and time values according to the given timestamp | 5.3 |
46 | date_get_last_errors() | Returns warnings and errors when creating a DateTime object | 5.3 |
47 | date_interval_create_from_date_string() | Creates a date interval from a given string | 5 |
48 | date_interval_format() | Formats a time interval | 5.5 |
49 | date_create_immutable_from_format() | Parses a time string according to the specified format | 5.5 |
50 | date_create_immutable() | Creates and returns a DateTimeImmutable object | 5.5 |
51 | timezone_version_get() | Returns the version of the current time zone database | 5.3 |
52 | timezone_location_get() | Returns location information related to the time zone | 5.3 |
Number | Constants and descriptions |
---|---|
1 | DATE_ATOM atomic (Example:2005-08-15T16:13:03 + 0000) |
2 | DATE_COOKIE HTTP Cookies (for example: Sun,2005year8month14day16:13:03 UTC) |
3 | DATE_ISO8601 ISO-8601(For example:2005-08-14T16:13:03 + 0000) |
4 | DATE_RFC822 RFC 822)(Example: Sun,2005year8month14day16:13:03 UTC) |
5 | DATE_RFC850 RFC 850 (Example: UTC 05year8month14day16:13:03) |
6 | DATE_RFC1036 RFC 1036(Example: UTC 05year8month14day16:13:03) |
7 | DATE_RFC1123RFC RFC 1123)(Example: Sun,2005year8month14day16:13:03 UTC) |
8 | DATE_RFC2822 RFC 2822(2005year8month14day, Sunday16:13:03 +0000) |
9 | DATE_RSS RSS (Sunday,2005year8month14day16:13:03 UTC) |
10 | DATE_W3C World Wide Web Consortium (for example:2005-08-14T16:13:03 + 0000) |
11 | SUNFUNCS_RET_TIMESTAMP timestamp (in5.1.2available in Chinese) |
12 | SUNFUNCS_RET_STRING hours:minutes (for example: 08:02)(in5.1.2available in Chinese) |
13 | SUNFUNCS_RET_DOUBLE hours as a floating-point number (for example8.75)(in5.1.2available in Chinese) |