Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.text.SimpleDateFormat;

public class Main {

    public static int timeCompare(String str1, String str2) {
        try {
            SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            java.util.Date begin = dfs.parse(str1);
            java.util.Date end = dfs.parse(str2);
            long between = end.getTime() - begin.getTime();
            if (between > 0) {
                return 1;
            } else if (between == 0) {
                return 0;
            } else {
                return -1;
            }
        } catch (Exception e) {
            return 1;
        }
    }
}