Java Hour Calculate diffHour(String day1, String day2)

Here you can find the source of diffHour(String day1, String day2)

Description

diff Hour

License

Open Source License

Declaration

public static int diffHour(String day1, String day2) throws ParseException 

Method Source Code


//package com.java2s;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    private static SimpleDateFormat dayParse = new SimpleDateFormat("yyyy-MM-dd");
    private static SimpleDateFormat seconParse = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static int diffHour(String day1, String day2) throws ParseException {
        Date parse = seconParse.parse(day1);
        Date parse2 = dayParse.parse(day2);
        long time = parse.getTime();
        long time2 = parse2.getTime();
        long diffTimes = time2 - time;
        int hours = (int) (diffTimes / 1000 / 60 / 60);
        return hours;
    }/*  w  w  w  .  ja  va2 s . c o  m*/
}

Related

  1. addHour(String now)
  2. addHours(int date, int hours)
  3. addNHours(Date date, int hours)
  4. getBothTime(String startTime, int hours)
  5. getCurrHourDate()
  6. getDelayEndTime(int hour, String timezone)
  7. getDelayTime(int hour, String date)