Skip to content

Instantly share code, notes, and snippets.

@kryvoboker
Created May 24, 2020 19:21
Show Gist options
  • Save kryvoboker/68774864161d47042999840dc461c54e to your computer and use it in GitHub Desktop.
Save kryvoboker/68774864161d47042999840dc461c54e to your computer and use it in GitHub Desktop.
HomeWork
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
/**
*
* @author kamaz
*/
public class Main {
public static void main(String[] args) {
Date dateOne = new Date();
Date dateTwo = new Date();
Scanner sc = new Scanner(System.in);
String text = "";
System.out.println("Input date dd:MM:yyyy");
text = sc.nextLine();
SimpleDateFormat sdf = new SimpleDateFormat("dd:MM:yyyy");
SimpleDateFormat sdf1 = new SimpleDateFormat("MM:yyyy");
try {
dateTwo = sdf.parse(text);
} catch (Exception e) {
System.out.println(e);
}
if (dateOne.compareTo(dateTwo) == 1 || dateOne.compareTo(dateTwo) == -1) {
System.out.println(sdf1.format(dateOne));
System.out.println(sdf1.format(dateTwo));
} else {
System.out.println(dateOne == dateTwo);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment