請教~兩時間如何比較後顯示出結果~問題~[已解决]
本帖最后由 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內顯示動態"目前時間"及"剩餘時間" http://www.autoitx.com/thread-19243-1-1.html
看看这个帖子也许有帮助 回复 2# netegg
感謝netegg的提供文獻~ 正在用力調適中~ 楼主难道是港澳台同胞
注意天数的计算,网上有很多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
有感謝 pcbar 版大的用力的提供,目前正套用您提供的"代碼" 謝謝~ 小弟是台胞,特來此請教~學習學習~
页:
[1]