Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static int compareDates(String dateTime1, String dateTime2, String format) {
        // 0 is equal, < 0 if date1 is less than date2
        try {
            SimpleDateFormat df = new SimpleDateFormat(format);
            Date date1 = df.parse(dateTime1);
            Date date2 = df.parse(dateTime2);
            return date1.compareTo(date2);

        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }
}