Java Timestamp Field getDurationMinute(Timestamp createTime, Timestamp finishTime)

Here you can find the source of getDurationMinute(Timestamp createTime, Timestamp finishTime)

Description

get Duration Minute

License

Apache License

Declaration

public static String getDurationMinute(Timestamp createTime, Timestamp finishTime) 

Method Source Code


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

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

public class Main {
    public static String getDurationMinute(Timestamp createTime, Timestamp finishTime) {
        String rtn = "0min";
        if (createTime == null) {
            return rtn;
        }//from  w  w  w .  j  a  v  a  2 s.c o m
        long ctime = createTime.getTime();
        BigDecimal ct = new BigDecimal(Long.toString(ctime));
        long ftime = System.currentTimeMillis();
        if (finishTime != null) {
            ftime = finishTime.getTime();
        }
        BigDecimal ft = new BigDecimal(Long.toString(ftime));
        BigDecimal a = ft.subtract(ct);
        BigDecimal o = new BigDecimal("0");
        if (a.compareTo(o) != 0) {
            BigDecimal thonsand = new BigDecimal("1000");
            BigDecimal b = a.divide(thonsand, 2);
            BigDecimal sixty = new BigDecimal("60");
            double du = b.divide(sixty, 2, BigDecimal.ROUND_HALF_UP).doubleValue();
            DecimalFormat format = new DecimalFormat("###.##");
            rtn = format.format(du) + "min";
        }
        return rtn;
    }
}

Related

  1. getDiffYear(java.sql.Timestamp start, java.sql.Timestamp end)
  2. getDiscrepancyNum(Timestamp time1, Timestamp time2)
  3. getDouble(Timestamp ts)
  4. getDuration(final Timestamp start, final Date end)
  5. getDurationHour(Timestamp time1, Timestamp time2, String direction)
  6. getEndTimeOfMonth(Timestamp timestamp)
  7. getEndTimeStampOfDate(Date date)
  8. getFormattedDateTimeColumn(final Timestamp ts, final SimpleDateFormat formatDate)
  9. getFormattedTimeStamp(long millisSince1970)