Java Day getdaysslice(String startdate, String enddate)

Here you can find the source of getdaysslice(String startdate, String enddate)

Description

getdaysslice

License

Open Source License

Declaration

public static int getdaysslice(String startdate, String enddate) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {

    public static int getdaysslice(String startdate, String enddate) {
        if (startdate == null || "".equals(startdate.trim()))
            return 0;
        if (enddate == null || "".equals(enddate.trim()))
            return 0;
        SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
        java.util.Date start = null;
        java.util.Date end = null;
        try {//w  w w .  j  a  v a 2s  . c o  m
            start = myFormatter.parse(startdate);
            end = myFormatter.parse(enddate);
        } catch (Exception e) {
            return 0;
        }
        long daynum = (end.getTime() - start.getTime()) / (24 * 60 * 60 * 1000);
        Calendar startcalendar = new GregorianCalendar();
        startcalendar.setTime(start);
        int n = 0;
        for (int i = 0; i <= daynum; i++) {
            if (startcalendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
                    || startcalendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
                startcalendar.add(Calendar.DAY_OF_MONTH, 1);
                continue;
            }
            startcalendar.add(Calendar.DAY_OF_MONTH, 1);
            n++;
        }
        return n;
    }

    public static String getTime() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(currentTime);
        String min;
        min = dateString.substring(14, 16);
        return min;
    }
}

Related

  1. getDaysforYear()
  2. getDaysFrom2Dates(Calendar calendar1, Calendar calendar2)
  3. getDaysLater(int day)
  4. getDaysMonthYear(Date date)
  5. getDaysOfDates(Date first, Date second)
  6. getDayStr(int i, String formatStr)
  7. getDayStringOfDate(Date date)
  8. getDayText(Date day)
  9. getDayTime_End()