JamesPTG Posted October 6, 2015 Share Posted October 6, 2015 (edited) Hello people, I have a date from a log who is set in Unix/Epoch time (like 1444077951) that I want to convert into a local time. I have try with this: _DateAdd('s', $unixdate, "1970/01/01 00:00:00") who work almost well because I have something like 2015/10/05 20:45:51 But actually this result is late from 2H from the time I should expect. I'm living in a TimeZone : +1 with the DST so I understand where is the problem, but how have the resultat with the local setting time ? I have try with this function : _Date_Time_SystemTimeToTzSpecificLocalTime But I don't understand how should I format the variable $pUTC.. Thank you Edited October 6, 2015 by JamesPTG Link to comment Share on other sites More sharing options...
Radiance Posted October 6, 2015 Share Posted October 6, 2015 #include <Date.au3> Global $Result = _GetHumanTimeFromUNIX("1444077951") MsgBox(0, "", $Result) Func _GetHumanTimeFromUNIX($UnixTime) Local $Seconds = $UnixTime + _GetCurrentGMTDiff() * 3600 Return _DateAdd("s", $Seconds, "1970/01/01 00:00:00") EndFunc Func _GetCurrentGMTDiff() Local $Struct = DllStructCreate("struct;long Bias;wchar StdName[32];word StdDate[8];long StdBias;wchar DayName[32];word DayDate[8];long DayBias;endstruct") Local $Result = DllCall("kernel32.dll", "dword", "GetTimeZoneInformation", "struct*", $Struct) If @error Or $Result[0] = -1 Then Return SetError(@error, @extended, 0) Return $Result[0] EndFunc zone97 1 Link to comment Share on other sites More sharing options...
mikell Posted October 6, 2015 Share Posted October 6, 2015 An other way...#include <Date.au3> $epoch = 1444077951 $aCall = DllCall("msvcrt.dll", "str:cdecl", "ctime", "int*", $epoch) $tmp = StringSplit($aCall[0], " ") For $i = 1 to 12 If $tmp[2] = _DateToMonth($i, $DMW_SHORTNAME) Then $tmp[2] = $i Next $date = StringFormat("%4i/%02i/%02i %8s", $tmp[5], $tmp[2], $tmp[3], $tmp[4]) msgbox(0,"", $date) zone97 and Radiance 2 Link to comment Share on other sites More sharing options...
zone97 Posted February 10, 2017 Share Posted February 10, 2017 Thank you both, very useful.. Spoiler WinSizer 2.1 (01/04/2017) - Download - [ Windows Layout Manager ]Folder+Program (12/23/2016) - Download - [ USB Shortcut Creator ] 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