关于 DateTimeFormat 格式问题
http://www.autoitx.com/thread-29136-1-1.html这个贴讲得不错不过我没用上这次把代码都发出来
MsgBox(0,"test",_GetSrv_Date())
;============================网络时间===================================================
Func _GetSrv_Date()
Local $_Srvlist = ["time-nw.nist.gov", _
"time-a.nist.gov", _
"time-b.nist.gov", _
"time-a.timefreq.bldrdoc.gov", _
"time-b.timefreq.bldrdoc.gov", _
"time-c.timefreq.bldrdoc.gov", _
"utcnist.colorado.edu", _
"time.nist.gov", _
"nist1.datum.com", _
"nist1.dc.glassey.com", _
"nist1.ny.glassey.com", _
"nist1.sj.glassey.com", _
"nist1.aol-ca.truetime.com", _
"nist1.aol-va.truetime.com"]
UDPStartup()
Local $_Time_Srv
For $x = 0 To UBound($_Srvlist) - 1
$_Time_Srv = $_Srvlist[$x]
Local $Socket = UDPOpen(TCPNameToIP($_Time_Srv), 123)
If @error <> 0 Then ContinueLoop
$Status = UDPSend($Socket, MakePacket())
If $Status = 0 Then ContinueLoop
Local $Data = "", $i = 0
While $Data = ""
$i += 1
$Data = UDPRecv($Socket, 100)
If $i = 5 Then ContinueLoop (2)
Sleep(88)
WEnd
UDPCloseSocket($Socket)
UDPShutdown()
ExitLoop
Next
If $Data = "" Then Return 0
$Data = UnsignedHexToDec(StringMid($Data, 83, 8))
$Data = _DateTimeFormat(_DateAdd("s", $Data, "1900/01/01"), 0)
Return $Data
EndFunc ;==>_GetSrv_Date
Func MakePacket()
Local $P, $D = "1b0e01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
While $D
$P &= Chr(Dec(StringLeft($D, 2)))
$D = StringTrimLeft($D, 2)
WEnd
Return $P
EndFunc ;==>MakePacket
Func UnsignedHexToDec($_Data)
Return Dec(StringTrimRight($_Data, 1)) * 16 + Dec(StringRight($_Data, 1))
EndFunc ;==>UnsignedHexToDec
怎么才能比如后门的时间是 2010-12-8 换成这样的格式 2011-12-08就要多个0 那位帮帮忙 本帖最后由 netegg 于 2011-12-10 18:02 编辑
绕个弯子吧
$Data = _DateTimeFormat(_DateAdd("s", $Data, "1900/01/01"), 0)
Return $Data
改成
dim $aData = stringsplit( _DateTimeFormat(_DateAdd("d", $Data, "1900/01/01"), 0), '/', 2)
return stringformat('%4d-%2d-%2d', $aData,$aData,$aData) 回复 2# netegg
非常感谢搞定了
不过纠正下 stringformat 里面的格式应该是'%4d-%02d-%02d'也多一个0
- -
页:
[1]