Php time format validation function example
This article describes a function used by php to verify the time format. it is used to check whether the format of the given time is correct. For more information, see. Run the following code to check whether the time entered by the user meets the requirements. Example:
"; $ Str =" 12:31:22 "; echo $ str."-"; echo isDatetime ($ str )? "TRUE": "FALSE"; echo "\ n"; $ str = "12:31:22"; echo $ str. "-"; echo isDatetime ($ str )? "TRUE": "FALSE"; echo "\ n"; $ str = "2012-02-10"; echo $ str. "-"; echo isDatetime ($ str, "Ymd ")? "TRUE": "FALSE"; echo "\ n"; $ str = "2012-02-10"; echo $ str. "-"; echo isDatetime ($ str, "Y-m-d ")? "TRUE": "FALSE";?> Output result: 12:31:22-FALSE 12:31:22-TRUE 2012-02-10-FALSE 2012-02-10-TRUECode description: convert the input time into a timestamp using strtotime and convert it to a specified format using the date function. if the converted string is the same as the input string, the format is correct. |