09-06
24

java 随机生成时间

private Color getRandColor(int fc, int bc) { // 给定范围获得随机颜色  
     Random random = new Random();  
    if (fc > 255)  
       fc = 255;  
    if (bc > 255)  
       bc = 255;  
    int r = fc + random.nextInt(bc - fc);  
    int g = fc + random.nextInt(bc - fc);  
    int b = fc + random.nextInt(bc - fc);  
    return new Color(r, g, b);  
   }

getRandColor(200, 250)




随机生成时间:
Random   rand   =   new   Random();
SimpleDateFormat   format   =   new   SimpleDateFormat( "yyyy-MM-dd ");
Calendar   cal   =   Calendar.getInstance();
cal.set(1900,   0,   1);
long   start   =   cal.getTimeInMillis();
cal.set(2008,   0,   1);
long   end   =   cal.getTimeInMillis();
for(int   i   =   0;   i   <   10;   i++)   {
Date   d   =   new   Date(start   +   (long)(rand.nextDouble()   *   (end   -   start)));
System.out.println(format.format(d));
}





文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: 随机 时间 颜色
相关日志:
评论: 0 | 引用: 0 | 查看次数: 603
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭