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

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

WBOY
WBOYOriginal
2016-10-10 11:56:271203browse

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

    echo 1;

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

Reply content:

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

    echo 1;

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

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>
Statement:
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