设置特定时区,WRT 当地时间

设置特定时区,WRT 当地时间

我正在尝试改编代码,从先前相关答案,我将其复制如下:

\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}

上述代码产生:

PDF 输出的屏幕截图,由上述代码的 LaTeX 编译生成。

然而,这很成问题:我身在蒙特利尔,时间差了 5 个小时。尽管我的本地时间(根据我机器的时钟)准确,但还是发生了这种情况。

我该如何设置特定时区以匹配蒙特利尔的时间?或者更简单一点,我可以让它读取我电脑上的时间吗?(您可以忽略 CEST 时间,因为它与我的问题无关。)

答案1

最后,下面的代码解决了我的问题:

\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{\DTMestnow}{\DTMtznow{-05}{+05}}

in Montreal: \DTMestnow
\end{document}

得出:

在此处输入图片描述

相关内容