I need the time to 1-second resolution.
datetime
uses \pdfcreationdate
for this, but only under pdf(La)TeX.
As a result under XeLaTeX, this:
\usepackage{datetime}
...
\newtimeformat{hhmmss}{\twodigit{\THEHOUR}\twodigit{\THEMINUTE}\twodigit{\THESECOND}}
\settimeformat{hhmmss}
\currenttime
always produces 00
as the last two digits, eg:
113600
Best Answer
There is no
\pdfcreationdate
command in XeTeX as in pdfTeX and LuaTeX. There is a technical reason, for this: the PDF file is produced by XeTeX in an asynchronous way, delivering the pages produced inxdv
format toxdvipdfmx
. In general, these files are kept in a temporary directory and the PDF is finally moved to the current directory at the end.One could use the shell escape, checking the date of creation of the
.log
file, which is opened at the start of the job, but this would be system dependent.Emulate
\pdfcreationdate
in XeTeXWe can use LuaTeX also from XeTeX (or XeLaTeX)! Create the following file
creationdate.lua
:Then put the following code before loading
datetime
:The file
creationdate.timestamp
will be removed, if existent, and a new one created with the current time in it, in a format similar to that produced by\pdfcreationdate
in pdfTeX. Then it will be read in; the time shown will be that of the execution of the script. However, any recent TeX distribution should havetexlua
(because it hasluatex
), so this should be as system independent as possible.Actually, what's written in
creationdate.timestamp
is something likeand then its contents is massaged a bit to get it into, essentially,
that's the format requested by
datetime
(theD
must have category code 12, because such is the one produced by\pdfcreationdate
in (pdf|Lua)TeX).A complete example, to be run with
--shell-escape
, as always (otherwise\pdfcreationdate
will not be defined anddatetime
will show seconds as "00"); the macros do nothing if\pdfcreationdate
is already present (so usingpdftex
orluatex
as engines).An alternative way on Unix systems
Unfortunately, XeTeX doesn't sport the pdfTeX feature of
\input|<command>
, so an indirect way has to be taken, creating an auxiliary file to be read in.creationdate.sh
Put the following in the file before loading
datetime
Then your commands will give the required result. Of course one must check that
stat
anddate
accept the required command line options.XeLaTeX must be run with the
-shell-escape
command line option, of course. If it isn't, then the behavior will be as without\pdfcreationdate
available, that is, the seconds will always be "00". If the file is processed with pdfLaTeX or LuaLaTeX, this definition of\pdfcreationdate
will be ignored anddatetime
will be happy nonetheless, as those engines already have\pdfcreationdate
.On Windows a suitable batch script can be devised.
Update July 2016
With the new
texosquery
script, the code can be simplified:I added
luatex85
in case LuaLaTeX is used. In this way,-shell-escape
is only needed for XeLaTeX. The\edef
with\detokenize
is necessary, because\TeXOSQueryNow
returns the startingD
with category code “letter” and the macros indatetime
assume category code “other” instead.Note: the Java application, at the moment, seems only to run with Java 1.7.0_52 or later, but I was successful in recompiling it on 1.7.0_45. It would be nice if the application was made usable also with previous versions of Java.