Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.util.Calendar;

public class Main {

    public static boolean isInTimeNow(int start, int end) {
        Calendar calendar = new ThreadLocal<Calendar>() {
            protected Calendar initialValue() {
                return Calendar.getInstance();
            }
        }.get();
        long current = System.currentTimeMillis();
        calendar.setTimeInMillis(current);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        long originToday = calendar.getTimeInMillis();
        long distance = current - originToday;
        if (start <= distance && distance <= end) {
            return true;
        }

        return false;
    }
}