Java Timestamp Field getDurationHour(Timestamp time1, Timestamp time2, String direction)

Here you can find the source of getDurationHour(Timestamp time1, Timestamp time2, String direction)

Description

get Duration Hour

License

Apache License

Declaration

public static String getDurationHour(Timestamp time1, Timestamp time2, String direction) 

Method Source Code

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

import java.sql.Timestamp;
import java.text.DecimalFormat;

public class Main {
    public static String getDurationHour(Timestamp time1, Timestamp time2, String direction) {
        String f = direction;/*from  w ww .  ja  va 2 s . com*/
        if (f == null) {
            f = "+";
        }
        long ctime1 = System.currentTimeMillis();
        long ctime2 = System.currentTimeMillis();
        if (time1 != null) {
            ctime1 = time1.getTime();
        }
        if (time2 != null) {
            ctime2 = time2.getTime();
        }
        int dur = 0;
        if ("+".equals(f)) {// time2-time1
            dur = (int) (((ctime2 - ctime1) / 1000) / 60);// min
        } else {
            dur = (int) (((ctime1 - ctime2) / 1000) / 60);// min
        }

        double dur_hour = (double) dur / 60;
        DecimalFormat format = new DecimalFormat("###.##");
        return format.format(dur_hour) + "hr";

    }
}

Related

  1. getDiffTime(Timestamp last)
  2. getDiffYear(java.sql.Timestamp start, java.sql.Timestamp end)
  3. getDiscrepancyNum(Timestamp time1, Timestamp time2)
  4. getDouble(Timestamp ts)
  5. getDuration(final Timestamp start, final Date end)
  6. getDurationMinute(Timestamp createTime, Timestamp finishTime)
  7. getEndTimeOfMonth(Timestamp timestamp)
  8. getEndTimeStampOfDate(Date date)
  9. getFormattedDateTimeColumn(final Timestamp ts, final SimpleDateFormat formatDate)