Skip to content

Instantly share code, notes, and snippets.

@aploskov
Created September 6, 2018 15:41
Show Gist options
  • Save aploskov/f5a40693acd54d5edc49bbb6d143fc0e to your computer and use it in GitHub Desktop.
Save aploskov/f5a40693acd54d5edc49bbb6d143fc0e to your computer and use it in GitHub Desktop.
Что я теперь знаю про сравнение дат. -_-
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