Java Month of Year sleepUntil(int year, int month, int day, int hour, int min, int sec)

Here you can find the source of sleepUntil(int year, int month, int day, int hour, int min, int sec)

Description

Sleeps the current thread until the specified future date.

License

Apache License

Parameter

Parameter Description
date a parameter

Declaration

public static void sleepUntil(int year, int month, int day, int hour, int min, int sec) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.Calendar;

public class Main {
    /**//from  w ww .j a  v  a  2  s .c om
     * Sleeps the current thread until the specified future date. If the date is before the current time,
     * the thread will resume operation immediately.
     * 
     * @param date
     */
    public static void sleepUntil(int year, int month, int day, int hour, int min, int sec) {
        Calendar cal = Calendar.getInstance();
        cal.set(year, month, day, hour, min, sec);

        long msFuture = cal.getTime().getTime();
        long msNow = System.currentTimeMillis();
        long msSleep = msFuture - msNow;

        if (msSleep <= 0) {
            return;
        }

        try {
            Thread.sleep(msFuture - msNow);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. isDefaultHolidays(int year, int month, int day)
  2. isWeekEnd(int year, int month, int day)
  3. Month_Of_Year(String Date, int MonthCase)
  4. monthLength(int month, int year)
  5. newInstance(int year, int month, int day)
  6. stringToMonth(String year, String month, boolean flag)
  7. sumDayByYearMonth(int year, int month)
  8. year(int month, int day, int hour, int minute, int second)
  9. yearMonth()