![LaTeX \usepackage{datetime} 및 \usepackage{scrtime}이 한 시간씩 벗어났습니다.](https://rvso.com/image/286970/LaTeX%20%5Cusepackage%7Bdatetime%7D%20%EB%B0%8F%20%5Cusepackage%7Bscrtime%7D%EC%9D%B4%20%ED%95%9C%20%EC%8B%9C%EA%B0%84%EC%94%A9%20%EB%B2%97%EC%96%B4%EB%82%AC%EC%8A%B5%EB%8B%88%EB%8B%A4..png)
LaTeX 파일에 현재 시간을 인쇄하고 싶지만 둘 다 \usepackage{datetime}
잘못된 \usepackage{scrtime}
시간을 표시하고 싶습니다. 다른 시간대로 수정할 수 있나요? 일광 절약 시간제를 조정하시겠습니까?
제가 글을 쓰고 있으니 https://www.sharelatex.com/
표시되는 서버 시간인 것 같습니다.
답변1
다음을 통해 시간대에 액세스할 수 있습니다 \pdfcreationdate
.
\documentclass{article}
\usepackage{etoolbox}
\def\parsepdfdatetime#1:#2#3#4#5#6#7#8#9{%
\def\theyear{#2#3#4#5}%
\def\themonth{#6#7}%
\def\theday{#8#9}%
\parsepdftime
}
\def\parsepdftime#1#2#3#4#5#6#7\endparsepdfdatetime{%
\def\thehour{#1#2}%
\def\theminute{#3#4}%
\def\thesecond{#5#6}%
\ifstrequal{#7}{Z}
{%
\def\thetimezonehour{+00}%
\def\thetimezoneminute{00}%
}%
{%
\parsepdftimezone#7%
}%
}
\def\parsepdftimezone#1'#2'{%
\def\thetimezonehour{#1}%
\def\thetimezoneminute{#2}%
}
\newcommand*{\thetimezone}{\thetimezonehour:\thetimezoneminute}
\begin{document}
\expandafter\parsepdfdatetime\pdfcreationdate\endparsepdfdatetime
This document was created on:
\theyear-\themonth-\theday\ \thehour:\theminute:\thesecond\ \thetimezone.
\end{document}
나에게는 다음이 표시됩니다.
편집하다:
이 정보를 사용하면 이제 다른 시간대로 변환할 수 있습니다. 아래 예는 Zulu 시간(+00:00)으로 변환됩니다.
\documentclass{article}
\usepackage{etoolbox}
\usepackage{pgfkeys,pgfcalendar}
\def\parsepdfdatetime#1:#2#3#4#5#6#7#8#9{%
\def\theyear{#2#3#4#5}%
\def\themonth{#6#7}%
\def\theday{#8#9}%
\parsepdftime
}
\def\parsepdftime#1#2#3#4#5#6#7\endparsepdfdatetime{%
\def\thehour{#1#2}%
\def\theminute{#3#4}%
\def\thesecond{#5#6}%
\ifstrequal{#7}{Z}
{%
\def\thetimezonehour{+00}%
\def\thetimezoneminute{00}%
}%
{%
\parsepdftimezone#7%
}%
}
\def\parsepdftimezone#1'#2'{%
\def\thetimezonehour{#1}%
\def\thetimezoneminute{#2}%
}
\newcommand*{\thetimezone}{\thetimezonehour:\thetimezoneminute}
\newcount\julianday
\newcount\dayofweek
\makeatletter
\newcommand*{\setzulutime}{%
\pgfcalendardatetojulian{\theyear-\themonth-\theday}{\julianday}%
%(\count@ is a temporary scratch count register)
% First adjust the minute offset if non-zero
\ifnum\thetimezoneminute=0\relax
\else
\count@=\theminute\relax
% Add or subtract the offset minute
\ifnum\thetimezonehour<0\relax
\advance\count@ by -\thetimezoneminute\relax
\else
\advance\count@ by \thetimezoneminute\relax
\fi
\edef\theminute{\number\count@}%
% Does the hour need adjusting?
\ifnum\count@<0\relax
\advance\count@ by 60\relax
\edef\theminute{\number\count@}%
% Need to subtract 1 from the hour
% but does the day need adjusting?
\ifnum\thehour=0\relax
\def\thehour{23}%
% Day needs adjusting.
\advance\julianday by -1\relax
\else
% Subtract 1 from the hour
\count@ = \thehour\relax
\advance\count@ by -1\relax
\edef\thehour{\number\count@}%
\fi
\else
% Minute isn't negative. Is it >= 60?
\ifnum\count@>59\relax
\advance\count@ by -60\relax
\edef\theminute{\number\count@}%
% Add 1 to the hour
\count@ = \thehour\relax
\advance\count@ by 1\relax
\edef\thehour{\number\count@}%
% Does the day need adjusting?
\ifnum\thehour=24\relax
\def\thehour{00}%
\advance\julianday by 1\relax
\fi
\fi
\fi
\fi
% Now adjust the hour offset if non-zero
\ifnum\thetimezonehour=0\relax
\else
\count@=\thehour\relax
\advance\count@ by \thetimezonehour\relax
% Does the day need adjusting?
\ifnum\count@<0\relax
\advance\count@ by 24\relax
\edef\thehour{\number\count@}%
\advance\julianday by -1\relax
\else
\ifnum\count@>23\relax
\advance\count@ by -24\relax
\edef\thehour{\number\count@}%
\advance\julianday by 1\relax
\else
\edef\thehour{\number\count@}%
\fi
\fi
\fi
\pgfcalendarjuliantodate{\julianday}{\theyear}{\themonth}{\theday}%
\pgfcalendarjuliantoweekday{\julianday}{\dayofweek}%
}
\makeatother
\begin{document}
\parsepdfdatetime D:20130408144644+01'00'\endparsepdfdatetime
This document was created on:
\theyear-\themonth-\theday\ \thehour:\theminute:\thesecond\ \thetimezone.
\setzulutime
UTC+00:00 time stamp:
\theyear-\themonth-\theday\ \thehour:\theminute:\thesecond.
\end{document}
이는 다음을 생성합니다.
답변2
실제로 시간만 사용자의 시간대에 맞게 조정하면 되므로 시간을 늘리거나 줄일 수도 있습니다.\현재시간에서 제공하는 등록날짜 시간패키지.
\documentclass{article}
\usepackage[nodayofweek]{datetime}
\begin{document}
% Format output
\ddmmyyyydate
% Un-adjusted
[Compiled \today, \currenttime]
\par
% advance the hour register by nr of hours
% negative values if you want to subtract
\advance\currenthour by 2
%Adjusted output
[Compiled \today, \the\currenthour:\the\currentminute]
\end{document}
결과는 다음과 같습니다.
메모이 해결 방법은 수동 확인이 필요합니다. 예를 들어, 컴파일 중인 sharelatex.com 서버가 다른 시간대에 있는 경우 그에 따라 출력이 변경됩니다.
편집하다: 요일 변경에 따라 시간을 조정할 때 날짜도 고려해야 한다는 사실을 방금 깨달았습니다. 예를 들어 서버 시간이 23:30인데 2시간 앞당기려는 경우...
이것을 빠른 수정으로만 고려하십시오.