Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.GregorianCalendar;

public class Main {

    public static int getDatePeriod(String startDate, String endDate) {

        String[] date1 = startDate.split("-");
        String[] date2 = endDate.split("-");
        GregorianCalendar gc1 = new GregorianCalendar(Integer.parseInt(date1[0]), Integer.parseInt(date1[1]),
                Integer.parseInt(date1[2]));
        GregorianCalendar gc2 = new GregorianCalendar(Integer.parseInt(date2[0]), Integer.parseInt(date2[1]),
                Integer.parseInt(date2[2]));
        long longDate1 = gc1.getTimeInMillis();
        long longDate2 = gc2.getTimeInMillis();
        long period = longDate2 - longDate1;
        period /= 24 * 60 * 60 * 1000;
        return (int) period;
    }
}