Android Date Interval Get getDiffHour(String startTime, String endTime)

Here you can find the source of getDiffHour(String startTime, String endTime)

Description

get Diff Hour

Declaration

public static int getDiffHour(String startTime, String endTime) 

Method Source Code

//package com.java2s;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static int getDiffHour(String startTime, String endTime) {
        long diff = 0;
        SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {//  ww  w . j a  va2s .  c  om
            Date startDate = ft.parse(startTime);
            Date endDate = ft.parse(endTime);
            diff = startDate.getTime() - endDate.getTime();
            diff = diff / (1000 * 60 * 60);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return Long.valueOf(diff).intValue();
    }
}

Related

  1. daysBetweenDate(Date date1, Date date2)
  2. getDiff(String startTime, String endTime)
  3. getDiff(String startTime, String endTime)
  4. getDiffDays(String startDate, String endDate)
  5. getDiffDays(String startDate, String endDate)
  6. getDiffHour(String startTime, String endTime)
  7. getFragment(Calendar calendar, int fragment, int unit)
  8. getFragment(Date date, int fragment, int unit)
  9. getFragmentInDays(Date date, int fragment)