Can strcmp compare two time-format strings?

Source: Internet
Author: User
Tags strcmp
strcmp ("2016-09-27", "2016-09-26") results are greater than 0, but can all the time formats be so compared?

Reply content:

strcmp ("2016-09-27", "2016-09-26") results are greater than 0, but can all the time formats be so compared?

If your purpose is only to compare the priorities, you can compare

It doesn't matter with the time format, but the time format of the numbers is actually comparable, except that the format of the date is the same

echo strcmp("2016-09-27","2016-9-26"); // -1echo strcmp("2016-11-27","2016-9-26"); // -1echo strcmp("2016-09-27","2016-09-26");// 1echo strcmp("2016-10-01","2016-09-26");// 1

strcmpThe string length is compared and A B is considered greater if the string string is longer than the length A B .
If the length of the string is equal, each character is compared, and the later word is greater than the previous word, until one of the words is greater than or less than the latter “字典顺序” , and the string is considered to be greater or smaller than the latter.
"2016-09-27" and "2016-09-26", comparing the character size until the '7' > '6' (ASCII), it is considered 2016-09-27 greater than 2016-09-26 , the same time format can be strcmp compared 实质上是字符串的比较 , Because the longer the back time the string size is always greater than the earlier time string.

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