Elegant method to generate array of random dates within two dates

前端 未结 4 1825
夕颜
夕颜 2020-11-30 21:17

I have a datepicker where I show two months and I want to randomly choose 3 dates in each visible month

  $(\'.date\').datepicker({
    minDate: new Date(),         


        
4条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 21:37

    You can convert the boundary dates to integers (Date.getTime()) and then use Math.random() to generate your random dates within given boundaries. Then go back to Date objects with Date.setTime().

提交回复
热议问题