Java Date to Day getDaysToLong(Date date1, Date date2)

Here you can find the source of getDaysToLong(Date date1, Date date2)

Description

get Days To Long

License

Open Source License

Declaration

public static Long getDaysToLong(Date date1, Date date2) 

Method Source Code

//package com.java2s;
/**//  w w  w .  j av a2  s.  c om
 * Project: guahao-portal-web-home
 * 
 * File Created at 2012-9-26
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */

import java.util.Calendar;
import java.util.Date;

public class Main {

    public static Long getDaysToLong(Date date1, Date date2) {
        Long d1 = getYmdTime(date1).getTime() / 1000;
        Long d2 = getYmdTime(date2).getTime() / 1000;
        return Math.abs((d2 - d1)) / (24 * 3600);
    }

    public static Date getYmdTime(Date date) {
        if (date == null) {
            return (new Date());
        }
        Calendar day = Calendar.getInstance();
        day.setTime(date);
        day.set(Calendar.HOUR_OF_DAY, 0);
        day.set(Calendar.MINUTE, 0);
        day.set(Calendar.SECOND, 0);
        day.set(Calendar.MILLISECOND, 0);
        Date convertTime = day.getTime();
        return convertTime;
    }
}

Related

  1. getDayShort(Date date)
  2. getDaysMin(Date d)
  3. getDaysPassedSince(Date dateLastModified)
  4. getDayStart(Date date)
  5. getDayStart(final Date date)
  6. getDayTime(Date date, int hour, int minute, int second)