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 {
    public static boolean isTomorrow(Date date) {
        boolean isTomorrow = false;

        Date currentDate = new Date();
        Date firstTimeToday = firstTimeOfDate(currentDate);
        long firstSecondInLong = firstTimeToday.getTime() / 1000;

        long firstOfTomorrowDate = firstSecondInLong + 24 * 60 * 60;
        long lastOfTomorrowDate = firstOfTomorrowDate + 24 * 60 * 60;

        long secondOfDate = date.getTime() / 1000;
        if (secondOfDate >= firstOfTomorrowDate && secondOfDate <= lastOfTomorrowDate) {
            isTomorrow = true;
        }

        return isTomorrow;
    }

    public static Date firstTimeOfDate(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(date.getTime());

        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        Date dateBegin = new Date();
        dateBegin.setTime(calendar.getTimeInMillis());
        return dateBegin;
    }
}