Что нового

Перевод секунд с начала эпохи Unix в дату

erlik

Продвинутый
Сообщения
317
Репутация
84
_GetDate_fromUnixTime путает время: сравните со своим часовым поясом.
Код:
ConsoleWRite('_GetDate_fromUnixTime (GM):'  & _GetDate_fromUnixTime(_GetUnixTime(), False, True) & @CRLF)   ;GM: 2014/04/07 13:05:44
ConsoleWRite('_GetDate_fromUnixTime (LT):'  & _GetDate_fromUnixTime(_GetUnixTime(), False,False) & @CRLF)   ;LT: 2014/04/07 17:05:44
ConsoleWrite('_Epoch_decrypt:'              & _Epoch_decrypt(_GetUnixTime()) & @CRLF)                       ;GM: 2014/04/07 09:05:44
ConsoleWRite('_TimeDOS_ToString (GM):'      & _TimeDOS_ToString(_GetUnixTime(),-1,'gmtime')  & @CRLF)       ;GM: 07/04/2014 09:05:44
ConsoleWRite('_TimeDOS_ToString (LT):'      & _TimeDOS_ToString(_GetUnixTime(),-1,'localtime')& @CRLF)      ;LT: 07/04/2014 13:05:44

Код:
;==============================================================
; Name...........: _TimeDOS_ToString
; Description ...: Decodes the DOS date and time into a string.
; Syntax.........: _TimeDOS_ToString($i_TimeStamp, $s_Format, $sTimeZone, $i_MaxLen)
; Parameters ....: $i_TimeStamp -  The number containing the DOS time.
;                  $s_Format    -  A format string to convert the timestamp to   (default - '%d/%m/%Y %H:%M:%S').
;                  $sTimeZone   -  A string specifying the time zone:  'localtime' or 'gmtime' (default - 'localtime').
;                  $i_MaxLen    -  Maximum length of the string to be returned  (default - 255).
; Return values .: Success      -  Formatted string with the decoded Date and Time.
;                  Failure      -  Empty string and sets the @error flag to non-zero.
; Author ........: Rob Saunders
; Modified.......: Garry_Galler
;==============================================================
Func _TimeDOS_ToString($i_TimeStamp, $s_Format, $sTimeZone='localtime', $i_MaxLen = 255)
	Local $struct_Time, $ptr_Time, $av_Time, $av_StrfTime

	If Not IsNumber($i_TimeStamp) Then
		Return SetError(1,-1,'')
	EndIf

    If $s_Format = -1 Or $s_Format = '' Then
        $s_Format='%d/%m/%Y %H:%M:%S'
    EndIf

	$ptr_Time = DllCall('CrtDll.dll', 'ptr:cdecl', $sTimeZone, 'long*', $i_TimeStamp)
	If @error Then
		Return SetError(@error,-2,'')
	EndIf

	$av_StrfTime = DllCall('CrtDll.dll', 'int:cdecl', 'strftime', _
		'str', '', _
		'int', $i_MaxLen, _
		'str', $s_Format, _
		'ptr', $ptr_Time[0])

	If (@error) Or Not (IsArray($av_StrfTime)) Then
		Return SetError(@error,-3, '')
	EndIf

	Return $av_StrfTime[1]
EndFunc
 
Верх