Which is the best way for checking if two Date() object are equals, with null safe feature?
Date d1
Date d2
d1 = null, d2 = new Date() => equal false
d1 = null, d2 = null => equal true
d1 = SAME_INSTANT, d2 = SAME_INSTANT => equal true
d1 = new Date(), d2 = YESTERDAY => equal false
Run Code Online (Sandbox Code Playgroud)
如果参数彼此相等,则返回 true,否则返回 false。因此,如果两个参数都为 null,则返回 true,如果正好有一个参数为 null,则返回 false。否则,通过使用第一个参数的 equals 方法确定相等。
| 归档时间: |
|
| 查看次数: |
2936 次 |
| 最近记录: |