Skip to content
⌘ NSIS Forum Archive

Convert Unix(Reg_Dword) To date

11 posts

r2du-soft#

Convert Unix(Reg_Dword) To date

i have a Unix(Reg_Dword) code,that are in registry Dword,that Unix(Reg_Dword) equal with a date:
55a61062 = 2015/07/15

and i have this Unix(Reg_Dword):
55a12943 = 2015/07/11

i have i program with vb6,that convert this Unix to date for me
now i need convert Unix(Reg_Dword) to date with nsis...
doing this is possible?how can?thanks
Anders#
It is easy to find information about converting a UNIX time_t to a Windows FILETIME and when you have that you can convert to SYSTEMTIME and this struct contains fields for each element of the date/time or you can format it according to the users locale. All of this has to be done with the system plugin...

Have you looked at http://nsis.sourceforge.net/Category...Time_Functions ?
r2du-soft#
thanks mr Anders
i see your link but i cant find sample that,please see this file:

this file in section one,give unix and after click on "convert Unix To Date" Program convert that Unix to date....

That is VB6 Code:
'Option Explicit

Private Type SYSTEMTIME
    wYear As Integer
    wMonth As Integer
    wDayOfWeek As Integer
    wDay As Integer
    wHour As Integer
    wMinute As Integer
    wSecond As Integer
    wMilliseconds As Integer
End Type

Private Type TIME_ZONE_INFORMATION
    Bias As Long
    StandardName(0 To 63) As Byte
    StandardDate As SYSTEMTIME
    StandardBias As Long
    DaylightName(0 To 63) As Byte
    DaylightDate As SYSTEMTIME
    DaylightBias As Long
End Type

Private Declare Function GetTimeZoneInformation Lib "kernel32" ( _
    ByRef TimeZoneInformation As TIME_ZONE_INFORMATION) As Long

Private Declare Function SystemTimeToTzSpecificLocalTime Lib "kernel32" ( _
    ByRef TimeZoneInformation As TIME_ZONE_INFORMATION, _
    ByRef UniversalTime As SYSTEMTIME, _
    ByRef LocalTime As SYSTEMTIME) As Long
    
Private Declare Function TzSpecificLocalTimeToSystemTime Lib "kernel32" ( _
    ByRef lpTimeZoneInformation As TIME_ZONE_INFORMATION, _
    ByRef lpLocalTime As SYSTEMTIME, _
    ByRef lpUniversalTime As SYSTEMTIME) As Long

Private Function ToLocal(ByVal UTCDateTime As Date) As Date
    Dim stUTC As SYSTEMTIME
    Dim stLocal As SYSTEMTIME
    Dim TimeZoneInfo As TIME_ZONE_INFORMATION

    With stUTC
        .wYear = Year(UTCDateTime)
        .wMonth = Month(UTCDateTime)
        .wDay = Day(UTCDateTime)
        .wHour = Hour(UTCDateTime)
        .wMinute = Minute(UTCDateTime)
        .wSecond = Second(UTCDateTime)
        .wMilliseconds = 0
    End With

    GetTimeZoneInformation TimeZoneInfo
    If SystemTimeToTzSpecificLocalTime(TimeZoneInfo, stUTC, stLocal) = 0 Then
        Err.Raise Err.LastDllError, _
                  "ToLocal", _
                  "System error calling SystemTimeToTzSpecificLocalTime"
    End If
    With stLocal
        ToLocal = DateSerial(.wYear, .wMonth, .wDay) _
                + TimeSerial(.wHour, .wMinute, .wSecond)
    End With
End Function

Public Function ToUTC(ByVal LocalDateTime As Date) As Date
    Dim stUTC As SYSTEMTIME
    Dim stLocal As SYSTEMTIME
    
    With stLocal
        .wYear = Year(LocalDateTime)
        .wMonth = Month(LocalDateTime)
        .wDay = Day(LocalDateTime)
        .wHour = Hour(LocalDateTime)
        .wMinute = Minute(LocalDateTime)
        .wSecond = Second(LocalDateTime)
        .wMilliseconds = 0
    End With
    Dim TimeZoneInfo As TIME_ZONE_INFORMATION
    
    GetTimeZoneInformation TimeZoneInfo
    If TzSpecificLocalTimeToSystemTime(TimeZoneInfo, stLocal, stUTC) = 0 Then
        Err.Raise Err.LastDllError, _
                  "ToUTC", _
                  "System error calling TzSpecificLocalTimeToSystemTime"
    End If
    With stUTC
        ToUTC = DateSerial(.wYear, .wMonth, .wDay) _
              + TimeSerial(.wHour, .wMinute, .wSecond)
    End With
End Function

Private Function DateToUnix(ByVal DateTime As Date) As Long
    'Unix Timestamps are always UTC.
    Dim Temp As Date
    
    Temp = ToUTC(DateTime)
    If Temp > #1/19/2038 3:14:07 AM# Then
        DateToUnix = DateDiff("s", #1/19/2038 3:14:08 AM#, Temp) _
                  Or &H80000000
    Else
        DateToUnix = DateDiff("s", #1/1/1970#, Temp)
    End If
End Function

Private Function UnixToDate(ByVal DWORD As Long) As Date
    'Unix Timestamps are always UTC.
    Dim Temp As Double

    Temp = CDbl(DWORD And &H7FFFFFFF)
    If DWORD < 0 Then
        UnixToDate = ToLocal(DateAdd("s", Temp, #1/19/2038 3:14:08 AM#))
    Else
        UnixToDate = ToLocal(DateAdd("s", Temp, #1/1/1970#))
    End If
End Function




Private Sub Command1_Click()
    Dim DT As Date
    DT = UnixToDate(CLng("&H" & txtTimestampIn.Text))
    lblDateTime.Caption = Format$(DT, "YYYY.MM.DD")
    lblTimestampOut.Caption = Right$(String$(7, "0") & Hex$(DateToUnix(DT)), 8)
End Sub
Anders#
I already told you the basic steps you have to do. Can you post the system plugin code you have? Converting to FILETIME can be done with the 64bit intop, the function calls are harder but please make a real effort on your own before I try to code something when I have time...
r2du-soft#
unix hex to date

Originally Posted by Anders View Post
I already told you the basic steps you have to do. Can you post the system plugin code you have? Converting to FILETIME can be done with the 64bit intop, the function calls are harder but please make a real effort on your own before I try to code something when I have time...
hi mr Anders
till this day im try for solve but really i cant,this is very hard for me 🙁
if is possible please help me for solve my problem
thanks
Anders#
It would go a lot faster if you just post the System code you already have so I don't have to write it all from scratch.

Try this:
#//support.microsoft.com/en-us/kb/167296#How To Convert a UNIX time_t to a Win32 FILETIME or SYSTEMTIME
StrCpy $0 0x55a61062
System::Int64Op $0 * 10000000
System::Int64Op 116444736000000000 +
System::Call KERNEL32::FileTimeToSystemTime(*ls,@r1) ; This requires NSIS 3.0b1
System::Call *$1(&i2.r1,&i2.r2,&i2,&i2.r3,&i2.r4,&i2.r5,&i2.r6,&i2.r7)
DetailPrint "$0 = $1/$2/$3 $4:$5:$6.$7"
r2du-soft#
thanks mr Anders
im try but i think this have a lot problem...

(My VB6 App) 55a61062= 2015/07/15_12:18:50 (But nsis show me=>) 2015/7/15_7:48:50.0
(My VB6 App) 55a12943= 2015/07/11_19:03:39 (But nsis show me=>) 2015/7/11_14:33:39.0
(My VB6 App) 55c52479= 2015/08/08_02:04:49 (But nsis show me=>) 2015/8/7_21:34:49.0
(My VB6 App) 55c52489= 2015/08/08_02:05:05 (But nsis show me=>) 2015/8/7_21:35:5.0
(My VB6 App) 55c52494= 2015/08/08_02:05:16 (But nsis show me=>) 2015/8/7_21:35:16.0

time difference is 04:30

Attach:
Anders#
Add System::Call KERNEL32::FileTimeToLocalFileTime(*ls,*l.s) before the FileTimeToSystemTime line to convert to the current users local time.
r2du-soft#
thanks master solve problem
and just have two question:
1- $7 show 0 ! that must show AM or PM?or other?
2- Date and time:
2015/08/08_02:05:16
2015/8/8_2:5:16.0
is equal but how can change 2015/8/8_2:5:16.0 to 2015/08/08_02:05:16 whit 0 before once numbers!?
thanks
r2du-soft#
Originally Posted by Anders View Post
1) Milliseconds, not used in UNIX time

2) Use IntFmt on each variable
Thanks Master,my Problem solved

intfmt $1 "%0.4d" $1
intfmt $2 "%0.2d" $2
intfmt $3 "%0.2d" $3
intfmt $4 "%0.2d" $4
intfmt $5 "%0.2d" $5
intfmt $6 "%0.2d" $6
intfmt $7 "%0.2d" $7