Function |
Description |
Instance |
Checkdate ($ month, $ date, $ year) |
If the value of the application constitutes a valid date, the function returns true. For example, if the error date is January 1, February 31, 2005, this function returns false. You can use this function to check the date and make it take effect before the date is used for calculation or storage in the database. |
<? Php // Returns false Echo checkdate (2,30, 2005 )? "Valid ": "Invalid "; // Returns true Echo checkdate (2010 )? "Valid ": "Invalid "; ?> |
Getdate ($ ts) |
If no independent variable exists, this function returns the current date and time in combination with an array. Each element in the array represents a specific component of the date/time value. You can submit optional time tag independent variables to the function to obtain the date/time value corresponding to the time tag. Use this function to obtain a series of discrete and easily separated date/time values. |
<? Php // Returns timestamp 13:15:23 7-Jun-2006 Echo mktime ); ?> |
Mktime ($ hour, $ Minute, $ Second, $ Month, $ day, $ Year) |
Function andGetdate ()Instead: it generates a UNIX time tag (the number of seconds since January 1, January 1, 1970 GMT) from a series of date and time values ). When no independent variable is needed, it generates the UNIX time tag for the current time. Use this function to obtain the UNIX time tag of real-time. This time label is usually used in many databases and programming languages. |
<? Php // Returns timestamp 13:15:23 7-Jun-2006 Echo mktime ); ?> |
Date ($ format, $ ts) |
This function format the UNIX time tag into a readable date string. It is the most powerful function in the PHP date/time API and can be used in a series of correction values to convert the integer time tag to the desired string format. Apply this function to display the formatting time or date. |
<? Php // Format current date // Returns "13-Sep-2005 PM" Echo date ("d-M-Y h: I A", mktime ()); ?> |
Strtotime ($ str) |
This function converts readable English date/time strings into UNIX time labels. Use this function to convert non-standard date/time strings into standard and compatible UNIX time labels. |
<? Php // Returns 13-Sep-05 Echo date ("d-M-y ", Strtotime ("today ")); // Returns 14-Sep-05 Echo date ("d-M-y ", Strtotime ("tomorrow ")); // Returns 16-Sep-05 Echo date ("d-M-y", strtotime ("today + 3 Days ")); ?> |
Strftime ($ format, $ ts) |
As defined by the setlocale () function, this function formats the UNIX time tag to a date string applicable to the current environment. Use this function to create a date string compatible with the current environment. |
<? Php // Set locale to France (on Windows) Setlocale (LC_TIME, "fra_fra "); // Format month/day names // As per locale setting // Returns "septembre" and "Mardi" Echo strftime ("Month: % B "); Echo strftime ("Day: % "); ?> |
Microtime () |
This function returns the number of seconds and microseconds that have elapsed since January 1, January 1, 1970, GMT. This function is applied when the execution time of a specific code block of the benchmark is accurately measured. |
<? Php // Get starting value $ Start = microtime (); // Run some code For ($ x = 0; $ x <1000; $ x ++ ){ ??? $ Null = $ x * $ x; } // Get ending value $ End = microtime (); // Calculate time taken Code Execution Echo "Elapsed time:". ($ end- $ Start). "sec "; ?> |
Gmmktime ($ Hour, $ Minute, $ Second, $ Month, $ day, $ Year) |
This function generates a UNIX time tag by a series of date and time values expressed in GMT. When no independent variable is needed, it generates a UNIX time tag of the current GMT real-time. This function is used to obtain UNIX time tags of GMT real-time. |
<? Php // Returns timestamp 12:25:23 9-Jul-2006 Echo gmmktime ); ?> |
Gmdate ($ format, $ ts) |
This function formats UNIX time tags into readable date strings. This date string is expressed in GMT (non-local time. This function is applied when the time tag is expressed in GMT. |
<? Php // Format current date into GMT // Returns "13-Sep-2005 08:32 AM" Echo gmdate ("d-M-Y h: I ", Mktime ()); ?> |
Date_default _ Timezone_set ($ Tz) and Date_default _ Timezone_get () |
All date/time function calls after this function are set and the default time zone is restored. Note: This function is only valid in PHP 5.1 +. This function is a convenient shortcut for future time operations. |
<? Php // Set timezone to UTC Date_default_timezone_set ('Utc '); ?> |