0

In trying to write some simple logging-to-file for an NSIS installer I had a lot of trouble finding a simple way of getting the current time.

There are no built-in functions, and most of the third-party headers or DLLs seem awfully heavyweight for just getting the current time.

What's the most straightforward way to get the current time in an NSIS script, preferably without a third-party library?

(I've answered this with what I'm probably going with, but if anyone has good alternatives please post them.)

Dogmatixed
  • 794
  • 1
  • 11
  • 33
  • This is a duplicate of http://stackoverflow.com/questions/2407509/writing-current-date-time-as-file-name-using-nsis – Paul Jansen Oct 29 '13 at 01:16
  • So it is! I didn't find that via google, nor did it come up as a possible dupe while I was writing this. That question does have valid alternatives, though I don't really like any of these methods. – Dogmatixed Oct 30 '13 at 18:06

1 Answers1

1

It looks like there is a function in the FileFunc.nsh header that comes with NSIS. It's primarily for getting file creation/modification times, but has a localtime option:

; leave the first 'filename' parameter empty and specify "L" in the second to get the current time
${GetTime} "" "L" $day $month $year $day_name $hours $minutes $seconds

I'm not sure why ther isn't a built in function or a standard GetLocalTime in a more common header than FileFunc.nsh

Dogmatixed
  • 794
  • 1
  • 11
  • 33