Search code examples
datetimestampnsis

Get date from timestamp in NSIS


I'm very new to NSIS, and I'm trying to get a date, hour, minutes, etc. from the given timestamp.

Is it any way to do that?

Thank you in advance for any answers...


Solution

  • !include LogicLib.nsh
    Section
    StrCpy $0 1568807339 ; UNIX time
    System::Int64Op $0 * 10000000
    System::Int64Op 116444736000000000 + ; support.microsoft.com/en-us/help/167296/how-to-convert-a-unix-time-t-to-a-win32-filetime-or-systemtime
    System::Call 'KERNEL32::FileTimeToLocalFileTime(*ls,*l.s)' ; This line is optional, comment it out if you want to keep it UTC
    System::Call 'KERNEL32::FileTimeToSystemTime(*ls,@r0)i.r1' ; NSIS v3+
    ${If} $1 <> 0
        System::Call '*$0(&i2.r1,&i2.r2,&i2,&i2.r3,&i2.r4,&i2.r5,&i2.r6)'
        IntFmt $2 "%.2d" $2
        IntFmt $3 "%.2d" $3
        IntFmt $4 "%.2d" $4
        IntFmt $5 "%.2d" $5
        IntFmt $6 "%.2d" $6
        DetailPrint "$1/$2/$3 $4:$5:$6"
    
        System::Call 'KERNEL32::GetDateFormat(i0x0400,i0,pr0,p0,t.r1,i666)'
        System::Call 'KERNEL32::GetTimeFormat(i0x0400,i0,pr0,p0,t.r2,i666)'
        DetailPrint "$1 $2"
    ${EndIf}
    SectionEnd