# How to change the timezone of my latex document irrespective of my computer time zone using datetime2?

I want to change the timezone format (say, I want to use always GMT-3 timezone). I am using the datetime2 package. Do I need to use the following command as mentioned in the manual?

\DTMdisplayzone{〈TZh〉}{〈TZm〉}

• Did you try this command out? Does it give the intended result? Or an error? Why do you think this command may or may not do what you want? Please clarify. Feb 22 at 12:16
• @marijn I actually don't know how to use this command. Could you please help me? Feb 22 at 12:23
• We can probably demonstrate the commands you need (or point you to other questions where they are used) but currently it is not really clear for me what you actually want to do. Could you explain (approximately) which input you want to provide in your document and which output you expect from that? Feb 22 at 14:03
• Whenever I use the command '\DTMnow' and compile, the time it shows, changes if I travel from one time zone to another. I want to fix the timezone so that, even if I shall visit, the time of the last compilation will be shown in the specified timezone (say CEST). Feb 22 at 17:33

The datetime2 package has a library for performing calculations on times and dates which can be loaded with \usepackage[calc]{datetime2}. This library provides two functions to convert from and to Zulu time (UTC+0). With these functions you can do a three-step approach: first convert the local time to Zulu time, second convert the Zulu time to the timezone you want to show, and third actually show the result of step two in the requested timezone.

In the MWE below I defined two new commands, one for converting to arbitrary time zones with two arguments for the offset and the reverse offset, and one shortcut command with the arguments pre-filled for Central European Summer Time (which is a bit odd since it is not summer at the moment, but in any case it is UTC+2, so Finland, the Baltics, most of the Balkan countries, some Middle Eastern countries, Egypt, Libya).

MWE:

\documentclass[en-MT]{article}
\usepackage[calc,useregional]{datetime2}
\begin{document}
\DTMsetstyle{en-MT-numeric}

\newcommand{\DTMtznow}[2]{%
% store current time in object 'now'
\DTMsavenow{now}%
% convert current time to UTC+0
\DTMtozulu{now}{currzulu}%
% add requested timezone offset to zulu time
\DTMsaveaszulutime{currcest}{\DTMfetchyear{currzulu}}{\DTMfetchmonth{currzulu}}{\DTMfetchday{currzulu}}{\DTMfetchhour{currzulu}}{\DTMfetchminute{currzulu}}{\DTMfetchsecond{currzulu}}{#2}{00}%
% display zulu+offset in requested timezone (= reverse offset)
\DTMdisplay{\DTMfetchyear{currcest}}{\DTMfetchmonth{currcest}}{\DTMfetchday{currcest}}{}{\DTMfetchhour{currcest}}{\DTMfetchminute{currcest}}{\DTMfetchsecond{currcest}}{#1}{00}%
}
% shortcut command for central european summer time (UTC+2)
\newcommand{\DTMcestnow}{\DTMtznow{+02}{-02}}

in current timezone: \DTMnow

in CEST: \DTMcestnow
\end{document}


Result:

• Thanks. It is working for me. [en-MT] part is just for styling, right? The code runs well without those two lines. Two questions - Why is there {+02} in \newcommand{\DTMcestnow}{\DTMtznow{+02}{-02}}? And how should I change this line if the difference between those two time zones is 2 hours and 30 minutes? Feb 24 at 2:07
• @PoreyS indeed en-MT is just for styling. The +02 and -02 are because you need to subtract to store the time in the requested timezone as UTC+0, and then provide the reverse timezone parameter to show the calculated UTC+0 time in the requested timezone again. It's a bit of a roundabout way, the datetime2 package is much more aimed at formatting dates and times than at calculating. For 30 minutes difference you should extend the command to accept two extra arguments #3 and #4 and use them instead of the two 00 values (right after the current #1 and #2). Feb 24 at 6:48