How do I make \today display the date according to my time zone?
If you need to display the date/time local to your timezone, you can change the TZ
(timezone) environment variable using a custom latexmkrc
file:
- In your project editor window, click on the “Upload” button on the top of the file tree panel.
- Select “New file”, and name the file
latexmkrc
(without extensions). - Add the following line to the file
latexmkrc
:$ENV{'TZ'}='Asia/Kuala_Lumpur';
or whichever timezone required. Here's a list of supported time zones for reference.
Dates and times (e.g. \today
and \DTMcurrenttime
from the datetime2
package) in the PDF should then give values local to the specified time zone.
The following example can be Opened in Overleaf using the link below. The latexmkrc
file— displayed beneath the LaTeX code—is created automatically.
main.tex
\documentclass{article}
\usepackage{datetime2}
\title{Changing Timezones Example}
\author{Overleaf}
\date{\today}
\begin{document}
\maketitle
The time right now in New York is \DTMcurrenttime.
\end{document}
latexmkrc
$ENV{'TZ'}='America/New_York';
Open this two-file example in Overleaf