GetFileTime ISO 8601
From NSIS Wiki
Jump to navigationJump to search
Author: Zinthose (talk, contrib) |
Description
Simple implementation to get the ISO_8601 formatted modified time of a file.
Usage
${GetFileTime_ISO_8601} $0 "Test.exe" DetailPrint "TimeStamp = $0" ; OutPut: TimeStamp = 2009-11-03T19:14:58Z
The Function
!define GetFileTime_ISO_8601 "!insertmacro _GetFileTime_ISO_8601" !macro _GetFileTime_ISO_8601 _VAR _FilePath ClearErrors Push $0 Push $1 GetFileTime "${_FilePath}" $1 $0 System::Int64Op $1 * 0x100000000 Pop $1 System::Int64Op $1 + $0 Pop $0 System::Call "*(&i2, &i2, &i2, &i2, &i2, &i2, &i2, &i2) i .r1" System::Call "Kernel32::FileTimeToSystemTime(*l r0, i r1)" System::Call "Kernel32::GetDateFormatA(i 0, i 0, i r1, t 'yyyy-MM-dd', t .r0, i ${NSIS_MAX_STRLEN})" System::Call "Kernel32::GetTimeFormatA(i 0, i 0, i r1, t 'THH:mm:ssZ', t .r1, i ${NSIS_MAX_STRLEN})" StrCpy $0 $0$1 Pop $1 Exch $0 Pop ${_VAR} !macroend
Alternative Version: Pseudo-code
You can also use the the File Function library header to achieve the same goal but I feel it's a bit heavy.
## The File Function header is required ; !include "FileFunc.nsh" ## Use the FileFunc GetTime function to get the FileTime ${GetTime} "${__FILE__}" "L" $0 $1 $2 $3 $4 $5 $6 ## Add Zero Padding to Hour Variable IntFmt $4 "%02i" $4 ## Format Output Value StrCpy $0 "$2-$1-$0T$4:$5:$6Z" ## Print Result DetailPrint "ISO_8601 = $0"