GetFileTime ISO 8601: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (→Usage: Corrected Output Example) |
m (Added Alternative using the FileFunc.nsh) |
||
Line 3: | Line 3: | ||
== Description == | == Description == | ||
Simple implementation to get the [http://en.wikipedia.org/wiki/ISO_8601 ISO_8601] formatted modified time of a file. | Simple implementation to get the [http://en.wikipedia.org/wiki/ISO_8601 ISO_8601] formatted modified time of a file. | ||
== Usage == | == Usage == | ||
<highlight-nsis> | <highlight-nsis> | ||
Line 40: | Line 39: | ||
</highlight-nsis> | </highlight-nsis> | ||
=== 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. | |||
<highlight-nsis> | |||
## 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" | |||
</highlight-nsis> | |||
[[Category:Disk, Path & File Functions]] | [[Category:Disk, Path & File Functions]] |
Latest revision as of 16:28, 24 November 2009
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"