找回密码
 加入
搜索
查看: 2572|回复: 4

[效率算法] 請教~兩時間如何比較後顯示出結果~問題~[已解决]

[复制链接]
发表于 2011-5-26 04:53:52 | 显示全部楼层 |阅读模式
本帖最后由 hifi 于 2011-5-26 11:21 编辑

以下小弟初步寫的...
結果都只有秒數
小弟要結果是如:  "剩餘時間 x年x月x日x時x分x秒"
請教有那位專家可提供更好方式...謝謝
#include <Date.au3>
$timeout = "2011/05/30" & " " & 05 & ":" & 00 & ":" & 00
While 1
        $timediff = _DateDiff('s', _NowCalc(), $timeout)
             MsgBox(0,"", $timediff )
WEnd
再請教如何在GUI內顯示動態"目前時間"及"剩餘時間"
发表于 2011-5-26 06:20:34 | 显示全部楼层
http://www.autoitx.com/thread-19243-1-1.html
看看这个帖子也许有帮助
 楼主| 发表于 2011-5-26 06:44:12 | 显示全部楼层
回复 2# netegg


感謝  netegg  的提供文獻~ 正在用力調適中~
发表于 2011-5-26 10:07:49 | 显示全部楼层
楼主难道是港澳台同胞
注意天数的计算,网上有很多js代码,天数计算都不对。
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Date.au3>
$mytime = "2049/10/01 00:00:00"

#Region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("倒计时:" & $mytime, 302, 89)
$Label1 = GUICtrlCreateLabel("", 8, 16, 284, 25)
$Label2 = GUICtrlCreateLabel("", 8, 50, 284, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

AdlibRegister("timer", 500)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
        EndSwitch
WEnd

Func timer()
        $nt = "当前时间:" & _NowCalc()
        If $nt <> GUICtrlRead($Label1) Then GUICtrlSetData($Label1, $nt)
        $year = _DateDiff("Y", _NowCalc(), $mytime)
        $mon = Mod(_DateDiff('M', _NowCalc(), $mytime), 12)
        ;Mod(_DateDiff('d', _NowCalc(), $mytime),365)每年的天数不一样
        If $mon > 0 Then
                $day = _DateDiff("D", _NowCalc(), $mytime) - _DateDiff("D", @YEAR & "/" & @MON + 1 & "/01", $mytime)
        Else
                $day = _DateDiff('D', _NowCalc(), $mytime)
        EndIf
        $hour = Mod(_DateDiff('h', _NowCalc(), $mytime), 24)
        $min = Mod(_DateDiff('n', _NowCalc(), $mytime), 60)
        $sec = Mod(_DateDiff('s', _NowCalc(), $mytime), 60)
        $djs = "距离设定时间还有: " & $year & "年" & $mon & "月" & $day & "日" & $hour & "时" & $min & "分" & $sec & "秒"
        If GUICtrlRead($Label2) <> $djs Then GUICtrlSetData($Label2, $djs)
EndFunc   ;==>timer
 楼主| 发表于 2011-5-26 10:55:28 | 显示全部楼层
有感謝 pcbar 版大的用力的提供,目前正套用您提供的"代碼" 謝謝~ 小弟是台胞,特來此請教~學習學習~
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-20 23:56 , Processed in 0.069732 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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