开发者

Set Date and Time in VBScript for Date object without changing system Date/Time

开发者 https://www.devze.com 2023-03-31 12:42 出处:网络
I got the problem in VBScript when the Date (including Now) always calls from Windows system Date/Time.

I got the problem in VBScript when the Date (including Now) always calls from Windows system Date/Time.

How can I set the Date/Time for VBScipt without configuring system Date/Time in Windows.

e.g.

When call Date in VBS, Date will return the current system date(if today date is 1/1/2001)

Dim settingDate
settingDate = Date
//settingDate = 1/1/2001

I would like something to hooking up the VBS code to get Date f开发者_StackOverflowrom we set without changing Windows System Date/Time from code

//Implement something to tell VBS that current date is 12/12/2000
Dim settingDate
settingDate = Date
//settingDate = 12/12/2000

Thanks


Just redefine Date(), Time(), Now(). POC script:

  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()

output:

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
0

精彩评论

暂无评论...
验证码 换一张
取 消