Php time format validation function example

Source: Internet
Author: User
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-TRUE

Code 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.