确保每天定时代码

練習生 2021-5-29 1068

Dim iRet = ""
Dim dTime = ""
Dim dTime_Now = "" //当前时间
Dim dDate_Now = ""//当前日期
Dim iRet_HourNow = "" //当前小时
Dim iRet_MinuteNow = ""//当前分钟
Dim dDate_implement = "" //执行时间

Do While True
    dTime_Now = Time.Now()
    dDate_Now = Time.Date()
    iRet_HourNow = Time.Hour(dTime_Now)
    iRet_MinuteNow = Time.Minute(dTime_Now)
    If iRet_HourNow = 11 And iRet_MinuteNow>=36 And dDate_Now<>dDate_implement  // dDate_Now<>dDate_implement  一天执行一次, iRet_MinuteNow>=36 超过分钟就可以执行 
        dDate_implement=dDate_Now
        TracePrint("dTime_Now="&Time.Format(dTime_Now,"yyyy-mm-dd hh:mm:ss"))
        TracePrint("dDate_Now="&Time.Format(dDate_Now,"yyyy-mm-dd hh:mm:ss"))
        TracePrint("iRet_HourNow="&Time.Format(iRet_HourNow,"yyyy-mm-dd hh:mm:ss"))
        TracePrint("iRet_MinuteNow="&Time.Format(iRet_MinuteNow,"yyyy-mm-dd hh:mm:ss"))
        TracePrint("dDate_implement="&Time.Format(dDate_implement,"yyyy-mm-dd hh:mm:ss"))
    End If
Loop



///第二种方式,感觉不够严谨


Dim sRet = ""
Dim temp = ""
Dim iRet = ""
Dim dTime = ""
Dim startDate= "" //开始日期
Dim  implementDate= "" //执行日期
Dim  startTime= "" //启动时间
Dim  currentTime= "" //当前时间

Do While True
    
    startDate  = Time.Date()
    startTime = Time.TimeSerial(10, 5, 0)
    currentTime = Time.Time()
    iRet = Time.DateDiff("s",startTime  ,currentTime)
    
    TracePrint("iRet="&iRet)    
    TracePrint(startTime&"启动时间="&Time.Format(startTime,"yyyy-mm-dd hh:mm:ss"))
    TracePrint(currentTime&"当前时间="&Time.Format(currentTime,"yyyy-mm-dd hh:mm:ss"))
    
    If iRet> 0 And startDate<>implementDate
        implementDate   =  startDate
        
        TracePrint(startDate&"startDate="&Time.Format(startDate,"yyyy-mm-dd hh:mm:ss"))
        TracePrint(startTime&"启动时间="&Time.Format(startTime,"yyyy-mm-dd hh:mm:ss"))
        TracePrint(currentTime&"当前时间="&Time.Format(currentTime,"yyyy-mm-dd hh:mm:ss"))
        TracePrint("iRet= IF"&iRet)
        
        TracePrint(implementDate&"执行日期="&Time.Format(implementDate,"yyyy-mm-dd hh:mm:ss"))
        
        TracePrint(startTime)
        Delay(5000)
    Else
        
        //TracePrint("Else")
    End If
Loop














最新回复 (2)
返回
发新帖