找回密码
 加入
搜索
查看: 222|回复: 3

关于if判断日期问题?

[复制链接]
发表于 2024-5-22 12:16:43 | 显示全部楼层 |阅读模式


想写个时间到期截止使用的,以下是论坛找到的获取时间代码,增加了一个判断,目前判断就出现问题,明明是大于,却不执行else的部分,求解
GetWebTime()

Func GetWebTime();获取网络时间的函数
        Local $www = Ping("www.baidu.com", 3000);
        Local $httpbaidu = ObjCreate("WinHttp.WinHttpRequest.5.1")
        $httpbaidu.Open("Get", "http://www.baidu.com", False);http://time.windows.com/?  http://www.baidu.com/?
        $httpbaidu.Send()
        Local $baidutimeGMT = $httpbaidu.GetResponseHeader("Date")

        Local $S = StringSplit("Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec", ",")
        For $i = 1 To 12
                $baidutimeGMT = StringReplace($baidutimeGMT, $S[$i], $i);返回格林尼治GMT时间,+8小时=北京时间
        Next

        $S = StringSplit($baidutimeGMT, ", :")
        ;local $tNew = _Date_Time_EncodeSystemTime($S[4],$S[3],$S[5],$S[6],$S[7],$S[8])
        ;5 4 3 6 7 8 中分别存放了  年月日时分秒
        ; $webtimeGMT=$S[5] &"/"& $S[4] &"/"& $S[3] &" "& $S[6] &":"& $S[7] &":"& $S[8]
        ;           年            月          日        时           分          秒
        ; MsgBox(0,"格林尼治时间是",$webtimeGMT)
        $webtimeBeiJing = $S[5] & $S[4] & $S[3]
        MsgBox(0, "北京时间是", $webtimeBeiJing)
        ;==>GetWebTime

;        If $webtimeBeiJing <"20241007" Then
$ver="20241007"
If $webtimeBeiJing >= $ver Then
                MsgBox(0, "提示", "时间大于")
                Exit

        Else
                MsgBox(0, "提示", "时间小于")
               
               
        EndIf
EndFunc   ;==>GetWebTime





发表于 2024-5-22 12:33:13 | 显示全部楼层
;~         $webtimeBeiJing = $S[5] & $S[4] & $S[3] 改为以下
        $webtimeBeiJing = StringFormat('%04d%02d%02d', $S[5], $S[4], $S[3])
 楼主| 发表于 2024-5-22 14:06:01 | 显示全部楼层
能否解释一下'%04d%02d%02d是什么意思,怎么来的?帮助文件没看懂
发表于 2024-5-23 00:39:11 | 显示全部楼层
basc 发表于 2024-5-22 14:06
能否解释一下'%04d%02d%02d是什么意思,怎么来的?帮助文件没看懂

%04d = 西元年四位數 例:2024
%02d = 月份,未滿10位數自動補0 例: 5月顯示 05月
%02d = 日期,未滿10位數自動補0 例: 23日顯示 23日,5日顯示05日

$webtimeBeiJing = StringFormat('%04d%02d%02d', $S[5], $S[4], $S[3]) ;<-- afan 板大代碼
MsgBox(0,"",$webtimeBeiJing)

時間顯示 20240523
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-16 04:44 , Processed in 0.076899 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表