Java Date Difference getDateDiffHour(String begindate, String enddate)

Here you can find the source of getDateDiffHour(String begindate, String enddate)

Description

get Date Diff Hour

License

Apache License

Declaration

public static long getDateDiffHour(String begindate, String enddate) 

Method Source Code

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

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static long getDateDiffHour(String begindate, String enddate) {
        long minuteDiff = getDateDiffMinute(begindate, enddate);
        Float hourDiff = (float) (minuteDiff / 60);
        return hourDiff.intValue();
    }/*from   ww w  .ja  v a 2s.c o m*/

    public static long getDateDiffMinute(String begindate, String enddate) {
        SimpleDateFormat formatter = new SimpleDateFormat(
                "yyyy-MM-dd kk:mm:ss");
        ParsePosition pos1 = new ParsePosition(0);
        ParsePosition pos2 = new ParsePosition(0);
        if (begindate.length() == 10)
            begindate = begindate + " 00:00:00";
        if (enddate.length() == 10)
            enddate = enddate + " 00:00:00";
        Date BeginDate = formatter.parse(begindate, pos1);
        Date EndDate = formatter.parse(enddate, pos2);
        long dateDiff = EndDate.getTime() - BeginDate.getTime();
        Float minuteDiff = (float) (dateDiff / 1000 / 60);
        return minuteDiff.intValue();
    }
}

Related

  1. getDateDiff(String startDt, String endDt)
  2. getDateDiff(String startTime, String endTime)
  3. getDateDiffDay(String begindate, String enddate)
  4. getDateDifference(String start, String end)
  5. getDateDifference(String startDateString, String endDateString)
  6. getDayDiff(Date firstDate, Date secondDate)
  7. getDiff(Date from, Date to)
  8. getDiffDate(String srcDate, String format, int diff)
  9. getDiffDays(Date from, Date to)