7.1 ⁎The datetime2 Package
The datetime2 package has replaced the now obsolete datetime package. This section is just a brief introduction, see the user guide [101] for other commands and settings not described here.
The simplest use of this package is:
\documentclass{article} \usepackage{datetime2} \begin{document} This PDF was created on \today. \end{document}
This produces
This is the default date format. If you want the full date, time and time zone, you can use
instead of \today
. This will display the date and time in the form
Note that XeLaTeX doesn't provide the time zone information so you will need to use PDFLaTeX or LuaLaTeX if you want this.
If you want to use a regional format, you can specify the region in the package option. For example:
\documentclass{article} \usepackage[en-GB]{datetime2} \begin{document} This PDF was created on \DTMnow. \end{document}
This produces:
If you want to pick up the regional setting from babel you
can use the useregional
option:
\documentclass[british]{article} \usepackage{babel} \usepackage[useregional]{datetime2} \begin{document} This PDF was created on \DTMnow. \end{document}
If you prefer a numeric regional format you can use
useregional=numeric
instead.
showdow
package option, but this
isn't available for all regions. You will need to check the
documentation for the relevant module to find out if it's supported.
If you want to display a particular date (without the time) in the current style you can use
where ⟨date⟩ is given in the format ⟨yyyy⟩-⟨mm⟩-⟨dd⟩. For example:
You can save a date and time for later use with:
where ⟨name⟩ is a unique label that identifies this date and time, and ⟨data⟩ is in the format
where ⟨YYYY⟩ is the year, ⟨MM⟩ is the month number, ⟨DD⟩ is the day of the month, ⟨hh⟩ is the hour (24), ⟨mm⟩ is the minute value, ⟨ss⟩ is the second value and ⟨zone⟩ is the time zone, which may be either Z or in the format ⟨TZh⟩:⟨TZm⟩ where ⟨TZh⟩ is the hour offset and ⟨TZm⟩ is the minute offset. The argument ⟨data⟩ may also be a control sequence that expands (one level) to the required format.
Alternatively, you can just save the date with:
where the ⟨date⟩ is in the format ⟨YYYY⟩-⟨DD⟩-⟨MM⟩ and ⟨name⟩ is again a label.
A previously saved date and time can be displayed in the current style using:
Just the date can be displayed using:
and just the time with:
In all cases, ⟨name⟩ is the label identifying the date or time stamp.
Here's an example that uses the en-GB
style:
\documentclass{article} \usepackage[en-GB]{datetime2} \newcommand*{\DateStamp}{2015-11-28T20:13:04Z} \DTMsavetimestamp{mydate}{\DateStamp} \DTMsavetimestamp{mydate2}{2014-06-01T09:01:58+01:00} \begin{document} Now: \DTMnow. Saved: \DTMuse{mydate}; \DTMuse{mydate2}. \end{document}
This produces
\DTMsavetimestamp
to fail. You
may need to temporarily switch off the shorthands. See the
babel manual [7] for further details.
This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-07-4).