2

I found that I can display \time writing \the\time, but this seems only to count minutes. So informally, the hours are \the\time / 60 and the minutes are \the\time % 60. But how can I get the form hh:mm from \time? Are there no seconds?

A question not related: \DTMnow provided by package datetime2 seems unrelated, as it is affected by SOURCE_DATE_EPOCH independent of FORCE_SOURCE_DATE. In that sense, behaves like metadata CreationDate.

Are there two implementations of time in parallel? If so, why?

1 Answer 1

3

\time always refers to the minute after midnight (as provided by your computer's clock) the TeX run started, unless you changed \time yourself.

With expl3 you can directly access the data:

\documentclass{article}

\ExplSyntaxOn

\NewExpandableDocumentCommand{\printtime}{}
 {
  \int_compare:nT { \c_sys_hour_int < 10 } { 0 }
  \int_eval:n { \c_sys_hour_int }
  :
  \int_compare:nT { \c_sys_minute_int < 10 } { 0 }
  \int_eval:n { \c_sys_minute_int }
 }

\ExplSyntaxOff

\begin{document}

Processing the present document started at \printtime.

\end{document}

enter image description here

If SOURCE_DATE_EPOCH and FORCE_SOURCE_DATE are set to a positive (integer) values, then \time and related counters are set accordingly. This is meant for reproducible PDF files, unaffected by the date metadata.

If I run

SOURCE_DATE_EPOCH=1 FORCE_SOURCE_DATE=1 pdflatex printtime.tex

I always get

enter image description here

and the metadata will be

CreationDate:    Thu Jan  1 01:00:01 1970 CET
ModDate:         Thu Jan  1 01:00:01 1970 CET

(this is affected by the time zone).

Why aren't seconds stored anywhere? Because they didn't make much sense when TeX was being written.

You can also have a look at texosquery:

\documentclass{article}
\usepackage{texosquery}

\texosquerydefpattern{\pattern}{\%2d/\%2M/\%4y \%2H:\%2m:\%2s}

\begin{document}

\TeXOSQueryDateTime{\thisdate}

Processing the present document started at
\expandafter\texosqueryfmtdatetime\expandafter\pattern\thisdate

\end{document}

enter image description here

Well, the seconds cannot be right, because the query is done after the processing has started.

2
  • could you explain a bit \printtime? It is quite complicated and I cannot even see where \time goes into. Commented Jun 21 at 9:38
  • @user2609605 The two integrr constants are automatically set at startup. The conditionals add a leading zero so you always get two digits.
    – egreg
    Commented Jun 21 at 11:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .