Java Hour getHoursOfTowDiffDate(String p_startDate, String p_endDate)

Here you can find the source of getHoursOfTowDiffDate(String p_startDate, String p_endDate)

Description

get Hours Of Tow Diff Date

License

Apache License

Declaration

public static long getHoursOfTowDiffDate(String p_startDate, String p_endDate) throws ParseException 

Method Source Code


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

import java.text.ParseException;

import java.util.Date;

public class Main {

    public static long getHoursOfTowDiffDate(String p_startDate, String p_endDate) throws ParseException {
        return (long) getMillisOfTowDiffDate(p_startDate, p_endDate) / (1000 * 60 * 60);
    }/*ww  w  .ja  va2  s  . c o  m*/

    public static long getMillisOfTowDiffDate(String p_startDate, String p_endDate) throws ParseException {
        Date l_startDate = toUtilDateFromStrDateByFormat(p_startDate, "yyyy-MM-dd HH:mm:ss");
        Date l_endDate = toUtilDateFromStrDateByFormat(p_endDate, "yyyy-MM-dd HH:mm:ss");
        long l_startTime = getMillisOfDate(l_startDate);
        long l_endTime = getMillisOfDate(l_endDate);
        return (long) (l_endTime - l_startTime);
    }

    public static long getMillisOfTowDiffDate(Date p_startDate, Date p_endDate) {
        long l_startTime = getMillisOfDate(p_startDate);
        long l_endTime = getMillisOfDate(p_endDate);
        return (long) (l_endTime - l_startTime);
    }

    public static java.util.Date toUtilDateFromStrDateByFormat(String p_strDate, String p_format)
            throws ParseException {
        java.util.Date l_date = null;
        java.text.DateFormat df = new java.text.SimpleDateFormat(p_format);
        if (p_strDate != null && (!"".equals(p_strDate)) && p_format != null && (!"".equals(p_format))) {
            l_date = df.parse(p_strDate);
        }
        return l_date;
    }

    public static long getMillisOfDate(java.util.Date p_date) {
        java.util.Calendar c = java.util.Calendar.getInstance();
        c.setTime(p_date);
        return c.getTimeInMillis();
    }
}

Related

  1. getHours()
  2. getHours(Date t, Date baseDate)
  3. getHours(final Date date)
  4. getHours(java.util.Date _date)
  5. getHoursByDate(Date date, int hours)
  6. getLastHour()
  7. getLasthour()
  8. getMinOfHour(long l1)
  9. getPreHour()