1

如何使用VB脚本在开始日期和结束日期之间随机生成日期和时间。我们必须从用户那里获取输入示例:startDate:15/09/2013 9:00:00 Enddate 21/09/2013 15:00:00

输出:随机日期:17/09/2013 12:00:00

4

1 回答 1

4

将小于以秒为单位的日期差的随机秒数添加到 startDate:

  Dim StartDate : StartDate = #15/09/2013 9:00:00#
  Dim Enddate   : Enddate   = #21/09/2013 15:00:01#
  Dim SecDiff   : SecDiff   = DateDiff("s", StartDate, Enddate)
  WScript.Echo StartDate, Enddate, SecDiff
  Dim n
  For n = 1 To 20
      WScript.Echo DateAdd("s", Fix(SecDiff * Rnd()), StartDate)
  Next

输出(德语语言环境):

15.09.2013 09:00:00 21.09.2013 15:00:01 540001
19.09.2013 18:49:56
18.09.2013 17:00:49
18.09.2013 23:55:40
17.09.2013 04:26:04
17.09.2013 06:17:32
20.09.2013 05:12:40
...
于 2013-09-24T17:11:24.313 回答