Created
September 6, 2018 15:41
-
-
Save aploskov/f5a40693acd54d5edc49bbb6d143fc0e to your computer and use it in GitHub Desktop.
Что я теперь знаю про сравнение дат. -_-
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example; | |
import java.util.Date; | |
public class Main { | |
public static void main(String[] args) { | |
final Date source = new Date(); | |
final Date prev = new Date(source.getTime() - 1000); | |
final Date same = new Date(source.getTime()); | |
final Date next = new Date(source.getTime() + 1000); | |
// final Date none = null; | |
System.out.println(source.compareTo(prev)); | |
System.out.println(source.compareTo(same)); | |
System.out.println(source.compareTo(next)); | |
// System.out.println(source.compareTo(none)); Null pointer exception. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment