Java Date to Timestamp compareDate(String timeStamp1, String timeStamp2)

Here you can find the source of compareDate(String timeStamp1, String timeStamp2)

Description

compare Date

License

Open Source License

Declaration

public static int compareDate(String timeStamp1, String timeStamp2) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006-2012//from w  w  w . ja  v  a2s.  c  o  m
 * Software Technology Group, Dresden University of Technology
 * DevBoost GmbH, Berlin, Amtsgericht Charlottenburg, HRB 140026
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *   Software Technology Group - TU Dresden, Germany;
 *   DevBoost GmbH - Berlin, Germany
 *      - initial API and implementation
 ******************************************************************************/

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    private static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss,SSS";

    public static int compareDate(String timeStamp1, String timeStamp2) {
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
        try {
            Date d1 = sdf.parse(timeStamp1);
            Date d2 = sdf.parse(timeStamp2);

            if (d1.compareTo(d2) == 0) {
                return -1;
            }
            return d1.compareTo(d2);
        } catch (ParseException e) {
        }
        return 0;

    }
}

Related

  1. dateToTimestamp(Date date)
  2. dateToTimestamp(Date date)
  3. dateToTimestamp(Date date)
  4. dateToTimestamp(Date date)