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
strcmp
The 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.