中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

java獲取隨機(jī)時(shí)間的代碼

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用
import java.text.parseexception;
 
    import java.text.simpledateformat;
 
    import java.util.date;
 
    public class getrandomtiem {
 
    //返回2011-01-01到2011-12-01的一個(gè)隨機(jī)日期
 
    public static void main(string []args){
 
    simpledateformat format = new simpledateformat("hh:mm:ss");
 
    date randomdate=randomdate("00:00:00","24:59:59");
 
    string randomdats="shi"+randomdate.gethours()+"f"+randomdate.getminutes()+"m"+randomdate.getseconds();
 
    system.out.println(randomdats);
 
    }
 
    /**
 
    * 獲取隨機(jī)日期
 
    * @param begindate 起始日期,格式為:yyyy-mm-dd
 
    * @param enddate 結(jié)束日期,格式為:yyyy-mm-dd
 
    * @return
 
    */
 
    private static date randomdate(string begindate,string enddate ){
 
    try {
 
    simpledateformat format = new simpledateformat("hh:mm:ss");
 
    date start = format.parse(begindate);//構(gòu)造開始日期
 
    date end = format.parse(enddate);//構(gòu)造結(jié)束日期
 
    //gettime()表示返回自 1970 年 1 月 1 日 00:00:00 gmt 以來(lái)此 date 對(duì)象表示的毫秒數(shù)。
 
    if(start.gettime() >= end.gettime()){
 
    return null;
 
    }
 
    long date = random(start.gettime(),end.gettime());
 
    return new date(date);
 
    } catch (exception e) {
 
    e.printstacktrace();
 
    }
 
    return null;
 
    }
 
    private static long random(long begin,long end){
 
    long rtn = begin + (long)(math.random() * (end - begin));
 
    //如果返回的是開始時(shí)間和結(jié)束時(shí)間,則遞歸調(diào)用本函數(shù)查找隨機(jī)值
 
    if(rtn == begin || rtn == end){
 
    return random(begin,end);
 
    }
 
    return rtn;
 
    }
 
    }

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:java快速排序算法代碼

下一篇: mahout實(shí)現(xiàn)基于用戶的Mahout推薦程序