Java Hour Calculate getDiffHour(String startTime, String endTime)

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

Description

get Diff Hour

License

Open Source License

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 {/*w  w w.j  a  v  a2s  . 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 new Long(diff).intValue();
    }
}

Related

  1. getBothTime(String startTime, int hours)
  2. getCurrHourDate()
  3. getDelayEndTime(int hour, String timezone)
  4. getDelayTime(int hour, String date)
  5. getDiffDateTime(int diff, int hours)
  6. getDoubleValue(String hours)
  7. getExpiresDate(int hours)
  8. getTime(String dateStr, int hour, String timeZone)
  9. getTimestampFromDateHour2(String d)