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

License

Apache License

Declaration

public static int getDiffHour(String startTime, String endTime) 

Method Source Code

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

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 {//from   w  w w . j  a  va  2  s  .  c  o  m
            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 new Long(diff).intValue();
    }
}

Related

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