Java Time Compare compareStringTime(String t1, String t2, String parrten)

Here you can find the source of compareStringTime(String t1, String t2, String parrten)

Description

compare String Time

License

Apache License

Declaration

public static long compareStringTime(String t1, String t2, String parrten) 

Method Source Code


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

import java.text.SimpleDateFormat;
import java.text.ParsePosition;

public class Main {

    public static long compareStringTime(String t1, String t2, String parrten) {
        SimpleDateFormat formatter = new SimpleDateFormat(parrten);
        ParsePosition pos = new ParsePosition(0);
        ParsePosition pos1 = new ParsePosition(0);
        java.util.Date dt1 = formatter.parse(t1, pos);
        java.util.Date dt2 = formatter.parse(t2, pos1);
        long l = dt1.getTime() - dt2.getTime();
        return l;
    }// w  w  w  . j av a 2s  .co  m

    public static String getTime(String parrten) {
        String timestr;
        if (parrten == null || parrten.equals("")) {
            parrten = "yyyyMMddHHmmss";
        }
        java.text.SimpleDateFormat sdf = new SimpleDateFormat(parrten);
        java.util.Date cday = new java.util.Date();
        timestr = sdf.format(cday);
        return timestr;
    }
}

Related

  1. compareTime(String time1, String time2)
  2. compareTime(String time1, String time2, String pattern)