Is there a way to include the document creation time with XeTeX?

I'm currently using \isodate{\today} \currenttime} to include an aproximate creation time for a XeTeX document. This is "good enough" but doesn't include the timezone. In pdflatex the creation time of a document can be included with \pdfcreationdate, is there an equivalent command that works with XeTeX?

This can be done by running an external program, for example, date on Unix systems. The output can be redirected to a file and then read by TeX. On Unix systems, also piping is possible.

Example:

\documentclass{article}

\immediate\write18{date >\jobname.date}

\begin{document}
Current time is: \input{\jobname.date}
\end{document}


The shell escape feature can be enabled by command line option -shell-escape (TeX Live) or --enable-write18 (MiKTeX).

• For Windows users, use \immediate\write18{date /t >\jobname.date}. – Friendly Ghost May 21 '15 at 10:11
• Thanks. However, I'm converting documents with pandoc (which doesn't yet have support for --latex-engine-opt) so was hoping to avoid anything that needs specific flags. – zzkt May 21 '15 at 10:33
• @nikgaffney In my answer I have listed the officially documented option names. They work regardless of the compiler (also in TeX, pdfTeX, LuaTeX). Nowadays, TL15 and MiKTeX seems to support each other option names: --enable-write18 and --shell-escape can both be used. – Heiko Oberdiek May 21 '15 at 10:51
• @nikgaffney Without the shell escape feature, the time resolution is date and time in minutes (\time) without time zone in XeTeX. But you can modify your build process to run the date command just before the pandoc command to generate the file with the full date inclusive time zone. – Heiko Oberdiek May 21 '15 at 10:54

Maybe you can use features provided by your editor. In case of emacs, you can use time-stamp. First, you have to adjust the variables time-stamp-format and time-stamp-pattern. I suggest using file local versions by putting something like this at the end of your document:

%%% Local Variables:
%%% mode: latex
%%% eval: (set (make-local-variable 'time-stamp-format) "%3a %02d/%02m/%4y %02H:%02M:%02S %Z")
%%% eval: (set (make-local-variable 'time-stamp-pattern) "\\\\newcommand{\\\\timestamp}{%%}")
%%% TeX-master: t
%%% End:


Next, you put the following in the first line of your document:

\newcommand{\timestamp}{}


followed by the rest of your LaTeX code. Each time you save your document, emacs automatically updates the argument of \timestamp and you can use the command in your document, e.g.:

\newcommand{\timestamp}{Don 21/05/2015 23:05:25 Mitteleuropäische Sommerzeit}

\documentclass{article}
\begin{document}
\texttt{Last saved: \timestamp}
\end{document}


is the result on my box.

• Thanks. it's a nice idea, but i was hoping to find something built in. The --shell-escape method or modifying the build process (as mentioned by @heiko-oberdiek above) fit a little better with the automated process i'm currently working with. – zzkt May 22 '15 at 8:40

There seems to be a package Datetime. This seems to print the time zone too. Using the command \DTMnow

Refer to http://ctan.org/pkg/datetime2

• Your answer would be greatly improved if you provided a full working example, starting with \documentclass, which shows your point. – Steven B. Segletes May 21 '15 at 11:05
• The package datetime2 supports seconds and time zone in case of pdfTeX, because pdfTeX provides this information in \pdfcreationdate. In case of XeTeX the package only provides the date and the time without seconds and time zone. – Heiko Oberdiek May 21 '15 at 21:36