Java Timestamp Format compareTimstampStr(String timestamp1, String timestamp2, String format)

Here you can find the source of compareTimstampStr(String timestamp1, String timestamp2, String format)

Description

compare Timstamp Str

License

Apache License

Declaration

public static int compareTimstampStr(String timestamp1, String timestamp2, String format) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

import java.util.Date;

public class Main {

    public static int compareTimstampStr(String timestamp1, String timestamp2, String format) {
        int result = 10;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
        long temp = 10L;
        try {//from w w  w .  j ava 2  s.  c  o m
            Date date1 = simpleDateFormat.parse(timestamp1);
            Date date2 = simpleDateFormat.parse(timestamp2);
            temp = date1.getTime() - date2.getTime();
        } catch (ParseException e) {
            result = 0x7fffffff;
            e.printStackTrace();
        }
        if (temp > 0L)
            result = 1;
        else if (temp == 0L)
            result = 0;
        else if (temp < 0L)
            result = -1;
        return result;
    }
}

Related

  1. decodeFileTimestamp(File file, Pattern filenamePattern, DateFormat dateFormat)
  2. format(BigDecimal data)
  3. format(Date aTs_Datetime)
  4. format(Date date)