vitalii_hrushyn
8/2/2016 - 8:56 PM

comparison of dates

comparison of dates

package com.gmail.vhrushyn;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println("INPUT DATE (in format dd:MM:yyyy)");
		String text = sc.nextLine();
		sc.close();
		
		Date date = new Date();
		Date currentDate = new Date();	
		
		SimpleDateFormat sdfD = new SimpleDateFormat("dd:MM:yyyy");
		
		try {
			date = sdfD.parse(text);
		} catch (ParseException e) {
			System.out.println(e);
		}
		
		String d = sdfD.format(date);
		String cd = sdfD.format(currentDate);
		String [] sd = d.split(":");
		String [] scd = cd.split(":");
		
		System.out.println(sdfD.format(currentDate)+" today");	
		for(int i = 0; i < 3; i++) {
			if (sd[i].equals(scd[i])) {
				
			}
			else {
				if (i == 0) {
					System.out.print("days");
				}
				if (i == 1) {
					System.out.print("months");
				}
				if (i == 2) {
					System.out.print("years");
				}
				System.out.println(" are differet: "+ sd[i]+" and "+scd[i]);
			}
		}
		if (sd[0].equals(scd[0]) && sd[1].equals(scd[1]) && sd[2].equals(scd[2])) {
			System.out.println("this dates are the same");
		}
	}
}