Home > Backend Development > PHP Tutorial > PHP7 string format time, how to compare the underlying implementation?

PHP7 string format time, how to compare the underlying implementation?

WBOY
Release: 2016-10-10 11:56:27
Original
1259 people have browsed it

<code>if('2016-9-10 12:01:08'<'2016-9-30 12:01:16')
{

    echo 1;

}
else
{
    echo 2;
}
上面的代码我发现真的可以 进行时间大小的比较,我想知道 是底层字符串对比还是转换成了时间戳?</code>
Copy after login
Copy after login

Reply content:

<code>if('2016-9-10 12:01:08'<'2016-9-30 12:01:16')
{

    echo 1;

}
else
{
    echo 2;
}
上面的代码我发现真的可以 进行时间大小的比较,我想知道 是底层字符串对比还是转换成了时间戳?</code>
Copy after login
Copy after login

It must be a string comparison and I won’t transfer it to you. You can try it

<code class="php">if('2016-9-33 12:01:08'<'2016-10-1 12:01:16')
{
    echo 1;
}else{
    echo 2;
}

if(strtotime('2016-9-33 12:01:08')<strtotime('2016-10-1 12:01:16'))
{
    echo 1;
}else{
    echo 2;
}</code>
Copy after login
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template