Generating Random Date time in java (joda time)

后端 未结 5 1585
心在旅途
心在旅途 2021-01-04 21:32

Is it possible to generate a random datetime using Jodatime such that the datetime has the format yyyy-MM-dd HH:MM:SS and it should be able to generate two random datetimes

5条回答
  •  误落风尘
    2021-01-04 21:56

    try

        Random r = new Random();
        long t1 = System.currentTimeMillis() + r.nextInt();
        long t2 = t1 + 2 * 60 * 1000 + r.nextInt(60 * 1000) + 1;
        DateTime d1 = new DateTime(t1);
        DateTime d2 = new DateTime(t2);
    

提交回复
热议问题