Java Milliseconds delayUntilNextSecond(int millis)

Here you can find the source of delayUntilNextSecond(int millis)

Description

delay Until Next Second

License

Open Source License

Declaration

static void delayUntilNextSecond(int millis) 

Method Source Code

//package com.java2s;
/**/*from  w w  w . ja v  a 2s .c o m*/
 * Logback: the reliable, generic, fast and flexible logging framework.
 * Copyright (C) 1999-2009, QOS.ch. All rights reserved.
 *
 * This program and the accompanying materials are dual-licensed under
 * either the terms of the Eclipse Public License v1.0 as published by
 * the Eclipse Foundation
 *
 *   or (per the licensee's choosing)
 *
 * under the terms of the GNU Lesser General Public License version 2.1
 * as published by the Free Software Foundation.
 */

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

public class Main {
    static void delayUntilNextSecond(int millis) {
        long now = System.currentTimeMillis();
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date(now));

        cal.set(Calendar.MILLISECOND, millis);
        cal.add(Calendar.SECOND, 1);

        long next = cal.getTime().getTime();

        try {
            Thread.sleep(next - now);
        } catch (Exception e) {
        }
    }
}

Related

  1. dateToMillis(Date date)
  2. dateToMillis(Date date)
  3. dateToMillis(long now)
  4. dayValue2Millisecond(int dayValue)
  5. decomposeMillis(long millis)
  6. diffInMillis(long instantOne, long instantTwo)
  7. diffMillisec(String lhs, String rhs)
  8. diffTimeInMillis(long start, long end)
  9. durationInMillis(long startNano)