QTP中时间的处理

自动化测试中,经常遇到页面需要输入时间,而这个时间很多时候是当前时间之后某个范围之类才有效。我们采用数据驱动时如果采用绝对时间,则数据复用性就很差了,数据需要经常修改。所以采用相对时间

 

下面的函数用于获取相对时间

'------------------------------------------------------------------------

'获取以当前时间为参照的偏移时间

'increTime: 偏移时间量,可使用负数 格式:day:hour:min:sec  1:3:8:23

'------------------------------------------------------------------------

Public Function GetTime(byval increTime)

       Dim y,m,d,h,n,s,timeArray

      

       timeArray = split(increTime,":",-1,1)

       d= timeArray(0)

       h= timeArray(1)

       n= timeArray(2)

       s= timeArray(3)

      

       GetTime = dateadd("d",d,now)

       GetTime = dateadd("h",h,GetTime)

       GetTime = dateadd("n",n,GetTime)

       GetTime = dateadd("s",s,GetTime)

      

       ' change to GE Time type

       Dim dateArr,timeArr

       timeArray = split(GetTime," ",-1,1)

       dateArr = split(timeArray(0),"-",-1,1)

       y = dateArr(0)

       m = ExpandByZero("L", dateArr(1),2)

       d = ExpandByZero("L", dateArr(2),2)

      

       timeArr = split(timeArray(1),":",-1,1)

       h = ExpandByZero("L", timeArr(0),2)

       n = ExpandByZero("L", timeArr(1),2)

       s = ExpandByZero("L", timeArr(2),2)

      

       GetTime = y  & "-" & m & "-" & d & " " & h & ":" & n & ":" & s

 

End Function

'------------------------------------------------------------------------

'0扩展当前字符串

'way: 扩展方式 L-左扩,R-右扩

'OrigStr: 原字符串

'HopeLen: 扩展后字符长度

'------------------------------------------------------------------------

Public Function ExpandByZero(byval way,byval OrigStr,byval HopeLen)

   Dim i,ZeroStr

   ZeroStr = ""

   For i =1 to HopeLen - len(OrigStr)

              ZeroStr = ZeroStr & "0"

   Next

   If way = "L" Then

              ExpandByZero = ZeroStr & OrigStr

       elseif way = "R" Then

              ExpandByZero = OrigStr & ZeroStr

       else

              Exit Function

   End If

End Function

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值