texblog

Date and time

I’m sure most of you have used \date{...} to print a date in a title (\maketitle) or letter. Probably you also know the more dynamic command \today to produce today’s date. Setting the date dynamically is not recommended (or even prohibited by some compilers) for usage in letters (i.e. \date{\today} or simply \date), since it makes tracing impossible.

Now what about time? Latex knows two packages that provide functionality related to time, datetime and KOMA-Script’s scrtime.

datetime:

\usepackage[option (see below)]{datetime}

\currenttime prints the actual time (hh:mm by default). In order to change the time format use:

\settimeformat{...}  with one of the following arguments:

xxivtime Twenty-four hour time, e.g. 22:28 (default).
hhmmsstime Twenty-four hour time, e.g. 22:28:00.
ampmtime Twelve hour time, e.g. 10:28pm.
oclock Displays the current time as a string, an interesting construct :-).

You may also use any of these directly in the preamble where you load the package as an option.

The datetime package easily let’s you adapt the time separator:

\renewcommand{\timeseparator}{.}

The complete documentation can be found here.

scrtime:

\usepackage[option]{scrtime}

The option 12h=true can be used for the 12h-time-format. However, there is no am/pm that is automatically added to the time.

The current time (hh:mm by default) is produced using:

\thistime

The separator can be set as optional argument, e.g. \thistime[.]. Furthermore, using the form \thistime* will not produce a zero in front of the minutes in case the number is below 10.

Use \settime{} to set a constant value for \thistime. I’m not sure how to undo it though.

The complete documentation can be found here as part of the KOMA-Script documentation (in German).

Finally, both packages include commands for date-formating which I will not further describe here. Please see the docmentation for details. In general, the “datetime” package offers more functionality and therefore probably is the better choice in most cases, unless you are using the KOMA-Script anyway.

Exit mobile version