-Ultima- Posted August 19, 2007 Share Posted August 19, 2007 (edited) I'm not sure if some Unix time converter has been submitted, but I've never seen one, so here's one I cooked up a while back. I don't know if there's a more efficient way to do this; this was just a straightforward conversion This function doesn't zero-pad any numbers, so if you want to format it into a readable string, you should take note that minutes and seconds less than 10 will look a bit funny if you don't pad them yourself._UnixTimeParse.au3expandcollapse popup#Include <Date.au3> Local $asDOTW[7] = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] Local $iUnixTime = 1111111111 Local $anDate = _UnixTimeParse($iUnixTime) MsgBox(0,"_UnixTimeParse(" & $iUnixTime & ")", StringFormat("%s %.2d/%.2d/%.2d At %.2d:%.2d:%.2d UTC", $asDOTW[$anDate[0]], $anDate[1], $anDate[2], $anDate[3], $anDate[4], $anDate[5], $anDate[6]))oÝ÷ Ù°Úµæ®ßöÚºÚ"µÍÒ[ÛYKSÛÙBÏOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOBÂÈØÜ[ÛÛÛÈHÚ][[^[YH[È[^HÛÛZ[[ÈHÈUÈ]Z][[[YKÈ[Y]ÊN ÌÍÛ[^[YHHH[^[YHÈÛÛÈ]Z[Y[ ÊNÛKÈ][YJÊN]È[^HÙHÜBÈÑVHÑÑQRÈ ËXÙY KQPTSÓVKÕTRSUKÑPÓÓKÈ]]ÜÊN[[XBÈÝJÊNHÛHÙH[XÈ[H]Y^HHËYYÈHH^HÙHÙYZÈØ[H[H[YH]ÙY[[[ÛY[ÂÈ [Û^JH[ Ý[^JBÂÏOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOB[ÈÕ[^[YTÙJ ÌÍÛ[^[YJBØØ[ ÌÍÚVYX^ÈHÍBØØ[ ÌÍØZS[Û^ÖÌLHHÌÌKÌKÌÌKÌÌKÌKÌÌKÌÌWBØØ[ ÌÍØ[]VÍ×HHÌËNMÌHÈ^HÙÙYZÈ ËXÙY KYX[Û^KÝZ[]KÙXÛÛÈÙXÛÛ ÌÍØ[]VÍHH[Ù ÌÍÛ[^[YK B ÌÍÛ[^[YHH[ ÌÍÛ[^[YKÍ BÈZ[]B ÌÍØ[]VÍWHH[Ù ÌÍÛ[^[YK B ÌÍÛ[^[YHH[ ÌÍÛ[^[YKÍ BÈÝ ÌÍØ[]VÍHH[Ù ÌÍÛ[^[YK B ÌÍÛ[^[YHH[ ÌÍÛ[^[YKÌ BÈ^HÙÙYZ ÌÍØ[]VÌHH[Ù ÌÍØ[]VÌJÉÌÍÛ[^[YK ÊBÈYXÚ[H ÌÍÛ[^[YH ÝÏH ÌÍÚVYX^ÂYÝ[Ù ÌÍØ[]VÌWK H[ ÌÍÚVYX^ÈHÍ[ÙB ÌÍÚVYX^ÈHÍB[Y ÌÍÛ[^[YHOH ÌÍÚVYX^ ÌÍØ[]VÌWH ÏHBÑ[È[ÛÚ[H ÌÍÛ[^[YH ÝÏH ÌÍØZS[Û^ÖÉÌÍØ[]VÌWB ÌÍÛ[^[YHOH ÌÍØZS[Û^ÖÉÌÍØ[]VÌWBY ÌÍØ[]VÌHHH[[Ù ÌÍØ[]VÌWK HH[ ÌÍÛ[^[YHOHB ÌÍØ[]VÌH ÏHBÑ[È^BY ÌÍÛ[^[YH È[ ÌÍØ[]VÌ×HH ÌÍØZS[Û^ÖÉÌÍØ[]VÌKLWJÌB[ÙB ÌÍØ[]VÌH ÏHB ÌÍØ[]VÌ×HH ÌÍÛ[^[YJÌB[Y] ÌÍØ[]B[[ÈÏOIÝ×Õ[^[YTÙEdit (2007-10-08): Added ability to calculate day of the week; 0 = Monday, ..., 6 = Sunday Edited October 8, 2007 by -Ultima- [ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ] Link to comment Share on other sites More sharing options...
GMK Posted August 20, 2007 Share Posted August 20, 2007 This could come in handy. However, since the Date UDF already uses the filename, "Date.au3," it might be a wise idea to rename your file, unless it is meant to be an addition to the existing Date.au3 include file, in which case users should not simply replace the file with yours, but copy and paste the function into the original Date.au3 UDF. But perhaps I'm insulting someone's intelligence. Otherwise, nice job. Link to comment Share on other sites More sharing options...
JRSmile Posted August 22, 2007 Share Posted August 22, 2007 (edited) if i'am not totally wrong there is already a date function to handle this problem #include <Date.au3> ; Calculated the number of seconds since EPOCH (1970/01/01 00:00:00) $iDateCalc = _DateDiff( 's',"1970/01/01 00:00:00",_NowCalc()) MsgBox( 4096, "", "Number of seconds since EPOCH: " & $iDateCalc ) EDIT: Sry GMK didn't notice that you already mentioned it. Edited August 22, 2007 by JRSmile $a=StringSplit("547275737420796F757220546563686E6F6C75737421","") For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4) Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI" Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile; MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-) Link to comment Share on other sites More sharing options...
-Ultima- Posted August 22, 2007 Author Share Posted August 22, 2007 (edited) That's not the same thing; what you're doing is getting the Unix timestamp, and what I'm doing is converting the Unix timestamp back into regular time.GMK wasn't really referring to the same thing either; he was mentioning the fact that I named the file as Date.au3, which can conflict with the existing Date.au3. He sorta had the right idea; I named my file accordingly only because I rewrote this function into a UDF by following the standard UDF writing guidelines. I guess it was wishful thinking on my part that the function might get added to the standard UDFs, but I'm not too worried if it doesn't get added either. Edited August 22, 2007 by -Ultima- [ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ] Link to comment Share on other sites More sharing options...
WeMartiansAreFriendly Posted October 10, 2008 Share Posted October 10, 2008 That's not the same thing; what you're doing is getting the Unix timestamp, and what I'm doing is converting the Unix timestamp back into regular time.GMK wasn't really referring to the same thing either; he was mentioning the fact that I named the file as Date.au3, which can conflict with the existing Date.au3. He sorta had the right idea; I named my file accordingly only because I rewrote this function into a UDF by following the standard UDF writing guidelines. I guess it was wishful thinking on my part that the function might get added to the standard UDFs, but I'm not too worried if it doesn't get added either.I've needed, but never wrapped my head around the conversion so this will really be useful. I don't see any reason for this not to be included with Time.au3. (There's so many useful functions on the forum that go unnoticed. ) Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
trancexx Posted October 10, 2008 Share Posted October 10, 2008 I've needed, but never wrapped my head around the conversion so this will really be useful. I don't see any reason for this not to be included with Time.au3. (There's so many useful functions on the forum that go unnoticed. )I agree. This function should, in fact, be built-in one (JS have it)....only not this one because it's wrong.Leap year definition in that script is wrong.And there is "days in current month" issue, looking at it. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
JRSmile Posted October 10, 2008 Share Posted October 10, 2008 ähhm, don't want to hurt you to much but here we already have such a function #include <date.au3> $unixtimestamp = "1111111111" $iDateCalc = _DateAdd('s', $unixtimestamp, "1970/01/01 00:00:00") MsgBox( 4096, "", "Timestamp converted to Date: " & $iDateCalc ) $a=StringSplit("547275737420796F757220546563686E6F6C75737421","") For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4) Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI" Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile; MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-) Link to comment Share on other sites More sharing options...
trancexx Posted October 10, 2008 Share Posted October 10, 2008 ähhm, don't want to hurt you to much but here we already have such a function #include <date.au3> $unixtimestamp = "1111111111" $iDateCalc = _DateAdd('s', $unixtimestamp, "1970/01/01 00:00:00") MsgBox( 4096, "", "Timestamp converted to Date: " & $iDateCalc )Where is "here"? I was commenting on built-innenes (probably not a word) and feelings of mrRevoked are impossible to predict at this moment. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
JRSmile Posted October 10, 2008 Share Posted October 10, 2008 (edited) in the good old date.au3 already in everybodys include folder ... it is called _DateAdd and lets you add seconds ( which are used to state the unix timestamp) to a date, lets take the 1970/01/01 00:00:00 which everybody knows is the starting date of the unix timestamp, and BINGO you got a unixtimestamp to date converter beware of leap years vacations and sundays and why build everything in if we can use udfs Edited October 10, 2008 by JRSmile $a=StringSplit("547275737420796F757220546563686E6F6C75737421","") For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4) Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI" Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile; MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-) Link to comment Share on other sites More sharing options...
WeMartiansAreFriendly Posted October 10, 2008 Share Posted October 10, 2008 I agree. This function should, in fact, be built-in one (JS have it)....only not this one because it's wrong.Leap year definition in that script is wrong.And there is "days in current month" issue, looking at it.I hope for a fix soon. Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now