Monday, 26 August 2013

PHP Date and Time Functions

These functions allow you to get the date and time from the server where your PHP scripts are running. You can use these functions to format the date and time in many different ways.

Installation:

There is no installation needed to use these functions; they are part of the PHP core.

Runtime Configuration

The behavior of the these functions is affected by settings in php.ini. All these parameters are available in PHP version 5 and onwards.
Date/Time configuration options:
NameDefaultDescriptionChangeable
date.default_latitude "31.7667"Specifies the default latitude.PHP_INI_ALL
date.default_longitude"35.2333"Specifies the default longitudePHP_INI_ALL
date.sunrise_zenith"90.83"Specifies the default sunrise zenithPHP_INI_ALL
date.sunset_zenith"90.83"Specifies the default sunset zenithPHP_INI_ALL
date.timezone""Specifies the default timezonePHP_INI_ALL

PHP: indicates the earliest version of PHP that supports the function.
FunctionDescriptionPHP
checkdate()Validates a Gregorian date3
date_create()Returns new DateTime object5
date_date_set()Sets the date5
date_default_timezone_get()Returns the default time zone5
date_default_timezone_set()Sets the default time zone5
date_format()Returns date formatted according to given format5
date_isodate_set()Sets the ISO date5
date_modify()Alters the timestamp5
date_offset_get()Returns the daylight saving time offset5
date_parse()Returns associative array with detailed info about given date5
date_sun_info()Returns an array with information about sunset/sunrise and twilight begin/end.5
date_sunrise()Returns the time of sunrise for a given day / location5
date_sunset()Returns the time of sunset for a given day / location5
date_time_set()Sets the time5
date_timezone_get()Return time zone relative to given DateTime5
date_timezone_set()Sets the time zone for the DateTime object5
date()Formats a local time/date3
getdate()Returns an array that contains date and time information for a Unix timestamp3
gettimeofday()Returns an array that contains current time information3
gmdate()Formats a GMT/UTC date/time3
gmmktime()Returns the Unix timestamp for a GMT date3
gmstrftime()Formats a GMT/UTC time/date according to locale settings3
idate()Formats a local time/date as integer5
localtime()Returns an array that contains the time components of a Unix timestamp4
microtime()Returns the microseconds for the current time3
mktime()Returns the Unix timestamp for a date3
strftime()Formats a local time/date according to locale settings3
strptime()Parses a time/date generated with strftime()5
strtotime()Parses an English textual date or time into a Unix timestamp3
time()Returns the current time as a Unix timestamp3
timezone_abbreviations_list()Returns associative array containing dst, offset and the timezone name5
timezone_identifiers_list()Returns numerically index array with all timezone identifiers5
timezone_name_from_abbr()Returns the timezone name from abbrevation5
timezone_name_get()Returns the name of the timezone5
timezone_offset_get()Returns the timezone offset from GMT5
timezone_open()Returns new DateTimeZone object5
timezone_transitions_get()Returns all transitions for the timezone5

PHP Date / Time Constants:

ConstantDescription
DATE_ATOMAtom (example: 2005-08-15T16:13:03+0000)
DATE_COOKIEHTTP Cookies (example: Sun, 14 Aug 2005 16:13:03 UTC)
DATE_ISO8601ISO-8601 (example: 2005-08-14T16:13:03+0000)
DATE_RFC822RFC 822 (example: Sun, 14 Aug 2005 16:13:03 UTC)
DATE_RFC850RFC 850 (example: Sunday, 14-Aug-05 16:13:03 UTC)
DATE_RFC1036RFC 1036 (example: Sunday, 14-Aug-05 16:13:03 UTC)
DATE_RFC1123RFC 1123 (example: Sun, 14 Aug 2005 16:13:03 UTC)
DATE_RFC2822RFC 2822 (Sun, 14 Aug 2005 16:13:03 +0000)
DATE_RSSRSS (Sun, 14 Aug 2005 16:13:03 UTC)
DATE_W3CWorld Wide Web Consortium (example: 2005-08-14T16:13:03+0000)
SUNFUNCS_RET_TIMESTAMPTimestamp ( Available in 5.1.2 )
SUNFUNCS_RET_STRINGHours:minutes (example: 08:02) ( Available in 5.1.2 )
SUNFUNCS_RET_DOUBLEHours as floating point number (example 8.75)( Available in 5.1.2 )

No comments:

Post a Comment