SPn*_*PnL -2 javascript jquery date date-comparison
I'm trying to compare two same dates in the browser console and getting the result as false. I don't understand how is it comparing as both the dates are the same?
$(function()
{
var d1 = new Date("01-12-2001");
var d2 = new Date("01-12-2001");
console.log(d1 == d2);
});Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>Run Code Online (Sandbox Code Playgroud)
but here if try to compare with GT and LT then its working.
It is checking for object equality. Compare the time instead.
$(function()
{
var d1 = new Date("2001-12-01");
var d2 = new Date("2001-12-01");
console.log(d1.getTime() == d2.getTime());
});Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
62 次 |
| 最近记录: |