当Date(包括Now)始终从Windows系统日期/时间调用时,我在VBScript中遇到了问题。
如何在不配置Windows系统日期/时间的情况下为VBScipt设置日期/时间。
e.g。
在VBS中调用日期时,日期将返回当前系统日期(如果今天日期是1/1/2001)
Dim settingDate
settingDate = Date
//settingDate = 1/1/2001
我想要连接VBS代码以获取我们设置的日期而不从代码更改Windows系统日期/时间
//Implement something to tell VBS that current date is 12/12/2000
Dim settingDate
settingDate = Date
//settingDate = 12/12/2000
由于
答案 0 :(得分:5)
重新定义Date(),Time(),Now()。 POC脚本:
WScript.Echo "Date()", Date()
WScript.Echo "Time()", Time()
WScript.Echo "Now()" , Now()
ExecuteGlobal Join( Array( _
"Function Date()" _
, " Date = #1/1/2012#" _
, "End Function" _
, "Function Time()" _
, " Time = TimeSerial( 1, 2, 3 )" _
, "End Function" _
, "Function Now()" _
, " Now = CDate( 4711.1147 )" _
, "End Function" _
), vbCrLf )
WScript.Echo "Date()", Date()
WScript.Echo "Time()", Time()
WScript.Echo "Now()" , Now()
输出:
Date() 26.08.2011
Time() 14:19:41
Now() 26.08.2011 14:19:41
Date() 01.01.2012
Time() 01:02:03
Now() 23.11.1912 02:45:10