Java Timestamp Compare dateDiff(Timestamp t1, Timestamp t2, int type)

Here you can find the source of dateDiff(Timestamp t1, Timestamp t2, int type)

Description

date Diff

License

Open Source License

Declaration

public static float dateDiff(Timestamp t1, Timestamp t2, int type) 

Method Source Code


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

import java.sql.Timestamp;

public class Main {
    public static float dateDiff(Timestamp t1, Timestamp t2, int type) {
        float i = t1.getTime() - t2.getTime();
        float f = 0.0f;// i / (1000 * 60);
        switch (type) {
        case 1:// hour
            f = i / (1000 * 60 * 60);//from  ww w . j a  v  a  2 s. c o m
            break;
        case 2:// min
            f = i / (1000 * 60);
            break;
        case 3:// sec
            f = i / (1000);
            break;
        case 0: // defaut is day
            f = i / (1000 * 60 * 60 * 24);
        }
        String temp = "#,##0.0";
        try {
            return Float.valueOf(new java.text.DecimalFormat(temp).format(f));
        } catch (Exception e) {
            ;// System.out.println(e);
        }
        return f;
    }
}

Related

  1. compareTimestamp(final Timestamp d1, final Timestamp d2)
  2. compareTimestamps(Timestamp minTimestamp, Timestamp maxTimestamp)
  3. compareTimestamps(Timestamp timestamp1, Timestamp timestamp2)
  4. dateDifference(Timestamp one, Timestamp two)