51Testing软件测试论坛

标题: QTP改变系统时间的方法 [打印本页]

作者: hxf    时间: 2007-2-28 17:23
标题: QTP改变系统时间的方法
dim oShell
For i=1 to 100
        a=year(date)
    b=month(date)
    c=day(date)
  if b= 2 then
          If c=28 Then
           set oShell=CreateObject("WSCript.shell")
                   b=b+1
                   c=1
                    f=a &"/"& b&"/"& c
              strcmd="cmd /k date " & f
          oShell.run strcmd
         else
                        set oShell=CreateObject("WSCript.shell")
                                        d=c+1
                                 f=a &"/"& b&"/"& d
                   strcmd="cmd /k date " & f
               oShell.run strcmd
          End If
elseif (b=1 or b=3 or b=5 or b=7 or b=8 or b=10 or b=12) then
  If c=31  Then
              b=b+1
                  c=1
            set oShell=CreateObject("WSCript.shell")
                         f=a &"/"& b&"/"& c
              strcmd="cmd /k date " & f
          oShell.run strcmd
else  
                        set oShell=CreateObject("WSCript.shell")
                                        d=c+1
                                 f=a &"/"& b&"/"& d
                   strcmd="cmd /k date " & f
               oShell.run strcmd
  End If
  else
     If (b=4 or b=6 or b=9 or b=11)  Then
                 If c=30 Then
            b=b+1
                   c=1
            set oShell=CreateObject("WSCript.shell")
                         f=a &"/"& b&"/"&c
              strcmd="cmd /k date " & f
          oShell.run strcmd
                   else
                        set oShell=CreateObject("WSCript.shell")
                                        d=c+1
                                 f=a &"/"& b&"/"& d
                   strcmd="cmd /k date " & f
               oShell.run strcmd
                 End If
end if
end if
Next









我是rain,如果有其他的代码问题,请提出来,我们相互学习。
作者: denisye    时间: 2007-2-28 17:26
呵呵,谢谢技能分享^_^
作者: zbyufeifei    时间: 2007-3-1 10:19
再加一个,对年的判断是否为闰年就更好了,要是2月29号存在怎么办呢?哈哈
作者: skyzhu    时间: 2007-3-2 18:02
标题: 那就再修改一把
Dim oShell
For i=1 To 5
    a=Year(Date)
    b=Month(Date)
    c=Day(Date)
    If b = 2 Then
        If a Mod 4 = 0 Then
            If c = 29 Then
                b = b+1
                c = 1
            Else
                c = c+1
            End If
        ElseIf c = 28 Then
            b = b+1
            c = 1
        Else
            c = c+1
        End If
    ElseIf (b=1 Or b=3 Or b=5 Or b=7 Or b=8 Or b=10 Or b=12) Then
        If (b = 12 And c = 31) Then
            b = 0
            a = a+1
        End If
        If c = 31 Then
            b = b+1
            c = 1
        Else
            c = c+1
        End If
    ElseIf (b=4 Or b=6 Or b=9 Or b=11) Then
            If c = 30 Then
                b = b+1
                c = 1
            Else
                c = c+1
            End If
    End If
    Set oShell=CreateObject("WSCript.shell")
    f = a &"/"& b &"/"& c
    strcmd = "cmd /c date " & f
    oShell.run strcmd
    WScript.Sleep 200
Next

[ 本帖最后由 skyzhu 于 2007-3-8 10:19 编辑 ]
作者: loho1968    时间: 2007-3-5 13:10
这个程序还有不完善,对闰年的处理不对。
其实何必自己编写程序,直接使用QTP的VBScript函数
function DateDemo(){
   var d, s = "Today's date is: ";           // 声明变量。
   d = new Date();                           // 创建 Date 对象。
   s += (d.getMonth() + 1) + "/";            // 获取月份。
   s += d.getDate() + "/";                   // 获取日。
   s += d.getYear();                         // 获取年份。
   return(s);                                // 返回日期。
}
作者: skyzhu    时间: 2007-3-5 13:30
原帖由 loho1968 于 2007-3-5 13:10 发表
这个程序还有不完善,对闰年的处理不对。
其实何必自己编写程序,直接使用QTP的VBScript函数
function DateDemo(){
   var d, s = "Today's date is: ";           // 声明变量。
   d = new Dat ...



GETXXX是JScript的东西吧
作者: mayuping0516    时间: 2007-5-31 09:33
顶一下  学习一下
作者: tiangou99073    时间: 2008-1-26 15:06
可以通过API改变吗?
作者: shanxi    时间: 2008-1-27 12:16
标题: 回复 8# 的帖子
这种API都相当多

楼主用的是Win下的Shell来实现的.




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2