Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static int days(String day1, String day2, String format) {
        DateFormat df = new SimpleDateFormat(format);
        long days = 0;
        try {
            Date d1 = df.parse(day1);
            Date d2 = df.parse(day2);
            long diff = Math.abs(d1.getTime() - d2.getTime());
            days = diff / (1000 * 60 * 60 * 24);
        } catch (Exception e) {
        }
        return (int) days;
    }
}