Java SQL Date Create getDays(Date from, Date to)

Here you can find the source of getDays(Date from, Date to)

Description

get Days

License

Open Source License

Declaration

public static long getDays(Date from, Date to) 

Method Source Code

//package com.java2s;

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

public class Main {

    public static long getDays(Date from, Date to) {

        long s = from.getTime();
        long e = to.getTime();

        return Math.round(((e - s) / (24 * 60 * 60 * 1000.0)));
    }//from   w  ww .ja v a2  s .  c  o m

    public static long getDays(String from, String to) {
        return getDays(parseDate(from), parseDate(to));
    }

    public static String getTime() {
        java.util.Date dt = new java.util.Date();
        java.sql.Timestamp ts = new java.sql.Timestamp(dt.getTime());
        String time = ts.toString();
        return time.substring(0, 19);
    }

    public static Date parseDate(String s) {
        Calendar c = Calendar.getInstance();
        try {
            int d = Integer.parseInt(s);
            int year = d / 10000;
            int month = (d % 10000) / 100;
            int day = d % 100;
            c.set(year, month - 1, day);
        } catch (Exception e) {
            return null;
        }
        return c.getTime();
    }
}

Related

  1. getDay(Date date)
  2. getDay(final java.sql.Date date)
  3. getDay(String stringDate)
  4. getDayByMonthSeed(Date date, int monthSeed)
  5. getDayByWeekString(Date date, String weekString)
  6. getDaysLater(Date date, int days)
  7. getDayStart(Date stamp)
  8. getLastDateOfQuarter()
  9. getLastDay(Date date)