zoukankan      html  css  js  c++  java
  • 产生随机时间的例子

    public class test{
        public static void main(String[] args) {          
                Date randomDate = randomDate("2012-06-01", "2012-12-12");
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                System.out.println(randomDate。toString());
        }
     
        private static Date randomDate(String beginDate, String endDate) {
            try {
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                Date start = format.parse(beginDate);// 开始日期
                Date end = format.parse(endDate);// 结束日期
                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 rtnn = begin + (long) (Math.random() * (end - begin));
            if (rtnn == begin || rtnn == end) {
                return random(begin, end);
            }
            return rtnn;
        }
    }
  • 相关阅读:
    CSS Nginx
    1 HTML入门
    Vue 高级使用
    Ajax快速入门
    JQuery快速入门
    02_Linux
    linux如何修改文件夹所属用户名和用户组
    max7219 八位数码管
    cmake qt hello word
    gcc section 标记
  • 原文地址:https://www.cnblogs.com/onmyway20xx/p/4194389.html
Copyright © 2011-2022 走看看