-
-
Save mariiaKolokolova/2ecf96e08d65f361a37dacf28c370883 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 maricka.kolokolova; | |
import java.text.ParseException; | |
import java.text.SimpleDateFormat; | |
import java.util.Calendar; | |
import java.util.Date; | |
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
Date dateToday = new Date(); | |
Date dateInput = new Date(); | |
String text; | |
SimpleDateFormat sdf = new SimpleDateFormat("dd:MM:yyyy"); | |
Scanner cs = new Scanner(System.in); | |
System.out.println("Input data"); | |
text = cs.nextLine(); | |
cs.close(); | |
try { | |
dateInput = sdf.parse(text); | |
} catch (ParseException e) { | |
e.printStackTrace(); | |
} | |
try { | |
dateToday = sdf.parse(sdf.format(dateToday)); | |
} catch (ParseException e) { | |
e.printStackTrace(); | |
} | |
System.out.println("Today :" + sdf.format(dateToday)); | |
System.out.println("Input date :" + sdf.format(dateInput)); | |
checkDate(dateToday, dateInput); | |
} | |
public static void checkDate(Date dateToday, Date dateInput) { | |
Calendar clToday = Calendar.getInstance(); | |
Calendar clInput = Calendar.getInstance(); | |
clToday.setTime(dateToday); | |
clInput.setTime(dateInput); | |
if (dateToday.equals(dateInput)) { | |
System.out.println("Dates are equals"); | |
} else if (clToday.get(Calendar.YEAR) != clInput.get(Calendar.YEAR)) { | |
System.out.println("Years are different. Today's year is " + clToday.get(Calendar.YEAR) + " inputed year " | |
+ clInput.get(Calendar.YEAR)); | |
} else if (clToday.get(Calendar.MONTH) != clInput.get(Calendar.MONTH)) { | |
System.out.println("Months are different. Today's month is " + (clToday.get(Calendar.MONTH) + 1) | |
+ " inputed month " + (clInput.get(Calendar.MONTH))); | |
} else if (clToday.get(Calendar.DAY_OF_MONTH) != clInput.get(Calendar.DAY_OF_MONTH)) { | |
System.out.println("Days are different. Today's day is " + clToday.get(Calendar.DAY_OF_MONTH) | |
+ " inputed day " + clInput.get(Calendar.DAY_OF_MONTH)); | |
} else { | |
System.out.println(-1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment