Java Timestamp Field getDiffDay(Timestamp time1, Timestamp time2)

Here you can find the source of getDiffDay(Timestamp time1, Timestamp time2)

Description

get Diff Day

License

Apache License

Declaration

@SuppressWarnings("deprecation")
    public static int getDiffDay(Timestamp time1, Timestamp time2) 

Method Source Code


//package com.java2s;
/*/*from   w  w w. j a v  a2  s .  c o  m*/
 * Copyright (c) 2014. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

import java.sql.Timestamp;

import java.util.Date;

public class Main {
    @SuppressWarnings("deprecation")
    public static int getDiffDay(Timestamp time1, Timestamp time2) {
        return getDay1(new Date(time2.getTime()), new Date(time1.getTime()));
    }

    @SuppressWarnings("deprecation")
    public static int getDay1(Date d1, Date d2) {
        if (d1 == null)
            return 1;
        d1.setHours(0);
        d1.setMinutes(0);
        d1.setSeconds(0);
        d2.setHours(0);
        d2.setMinutes(0);
        d2.setSeconds(0);
        long date1 = d1.getTime() / (1000l * 60 * 60 * 24);
        long date2 = d2.getTime() / (1000l * 60 * 60 * 24);
        return Long.valueOf(date2 - date1).intValue();
    }
}

Related

  1. getDayOfWeek(Timestamp timestamp)
  2. getDaysBetween(Timestamp start, Timestamp end)
  3. getDayStartTimestamp()
  4. getDayTime(Timestamp day, Timestamp time)
  5. getDefaultTimestamp()
  6. getDifferenceInHours(Timestamp startDateTime, Timestamp endDateTime)
  7. getDiffSecond(long orgTimestamp, long desTimestamp)
  8. getDiffTime(Timestamp last)
  9. getDiffYear(java.sql.Timestamp start, java.sql.Timestamp end)