如何使用 autohotkey 获取一周的日期

how to get a week's date with autohotkey

我正在使用 autohotkey 处理日期,我需要赶上一周前的一天

例子

如果今天是28号那我就得取上周的21号

calendar

在下面的脚本中我取当前日期

FormatTime, date, , dd/MM/yyyy
MsgBox %date%

我什至想到了一个逻辑,用今天减去一周前一天的7。我需要帮助来创建更好的脚本

28 - 7 = 21

如果有人能帮助我谢谢:)

当您遇到月份之间的变化时,只减去数字是不好的。
必须为此创建自定义逻辑。

幸运的是 AutoHotkey 的 += 运算符支持 date/time math.
这就是您所需要的:

;we're starting off the date1 variable as blank,
;which means the current time will be used.
date1 += -7, days 
FormatTime, finalDate, % date1, dd/MM/yyyy ;format the result to our desired format
MsgBox, % finalDate

我就是这样做的

FormatTime, date_, , dd
sub += date_-7
FormatTime date, , /MM/yyyy
MsgBox,%sub%%date%