Getting current time inside groff

Last-Updated: 2021-08-30


Getting current time in groff documents

Several number registers are available to get the current time from groff itself. They are defined (troff/input.cpp) like so:

If you want to, you can also get the time from another programming language, here Perl: (2000-04/msg00040)

.sy perl -e 'printf ".nr H %d\\ M %d\\ S %d\\n",\
            (localtime(time))[2,1,0]' > /tmp/x\n[$$]
.so /tmp/x\n[$$]
.sy rm /tmp/x\n[$$]

A third option would be to store the result of a command in a string with the -d option flag as suggested by Steve Izma (2000-04/msg00040), and then reference the string in your document.

groff -dcur_time="`date`" [your other options] filename

In your document, you can then print the date with \*[cur_time].

← Go back