java 生成随即日期

    技术2022-05-19  26

    import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Random; public class runMain {     /**      * @param args      */     public static Logger log = Logger.getLogger(runMain.class);     public static void main(String[] args) {           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   <   243;   i++)   {         Date   d   =   new   Date(start   +   (long)(rand.nextDouble()   *   (end   -   start)));         System.out.println(format.format(d));         }     } }


    最新回复(0)