Here you can find the source of getRandomTimeRound(int _duration, TimeUnit _unit)
Parameter | Description |
---|---|
_duration | a parameter |
_unit | a parameter |
private static Date getRandomTimeRound(int _duration, TimeUnit _unit)
//package com.java2s; /**//from w w w .j av a2s. c om * PureInfo Peach2 * @(#)QuartzJobUtil.java 1.0 2008-12-19 * * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. * All rights reserved, see the license file. * * www.pureinfo.com.cn */ import java.util.Date; import java.util.Random; import java.util.concurrent.TimeUnit; public class Main { /** * get random time in druation whit time unit from now. * * @param _duration * @param _unit * @return */ private static Date getRandomTimeRound(int _duration, TimeUnit _unit) { if (_duration < 0) { return new Date(); } int i = new Random().nextInt(_duration); return new Date(new Date().getTime() + TimeUnit.MILLISECONDS.convert(i, _unit)); } }