在上一个主题中: 日期计算:加 n 天
我想将 \DueDate{2019/10/26}{15} 更改为新格式:\DueDate{26/10/2019}{15}
预先感谢
代码:
\documentclass[10pt]{article}
\usepackage[calc,datesep=/]{datetime2}
\newcount\daycount
\newcommand{\DueDate}[2]{%
\DTMsavedate{ShootDate}{#1}%
\DTMsaveddateoffsettojulianday{ShootDate}{#2}\daycount
\DTMsavejulianday{ShootDate}{\number\daycount}%
\DTMusedate{ShootDate}%
}
\begin{document}
26/10/2019 + 15 day = \DueDate{26/10/2019}{15}
14/11/2019 + 30 day = \DueDate{2019-11-14}{30}
05/03/2020 + 45 day = \DueDate{2020-03-05}{45}
\end{document}
答案1
这个选项怎么样 -\DueDate{<day>/<month>/<year>}{<adv>}
使用规定的格式解析日期并使用advdate
将日期向前移动<adv>
几天:
\documentclass{article}
\usepackage{advdate}
\makeatletter
\def\settoday#1/#2/#3\relax{\ThisDay{#1}\ThisMonth{#2}\ThisYear{#3}}
\newcommand{\DueDate}[2]{%
\expandafter\settoday#1\relax
\AdvanceDate[#2]%
\number\day/\number\month/\number\year
%\two@digits{\day}/\two@digits{\month}/\number\year% Two digits for month/day
}
\makeatother
\begin{document}
26/10/2019 + 15 day = \DueDate{26/10/2019}{15}
14/11/2019 + 30 day = \DueDate{14/11/2019}{30}
05/03/2020 + 45 day = \DueDate{5/3/2020}{45}
11/12/2013 + 1 day = \DueDate{11/12/2013}{1}
\end{document}
如果需要,您可以使用“两位数”格式: