Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

public class Main {
    /**
     * Get relativy days base on today, will return negative and positive
     * values.
     * 
     * @param d
     * @return
     */
    public static long getRelativeDays(Date d) {
        Calendar c = Calendar.getInstance();
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        long curMilli = c.getTimeInMillis();
        c.setTimeInMillis(d.getTime());
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        long dMilli = c.getTimeInMillis();
        return (dMilli - curMilli) / (1 * 24 * 3600 * 1000);
    }
}