Loading
0

AHK实现返回下个月的最后一天,超级好用

方案一

;-- last day of month -------------------------
month :=2, year :=2020
MsgBox, % SubStr("0" month,-1) "/" LDOM(year SubStr("0" month,-1)) "/" year

LDOM(TimeStr="")
{
	if	!TimeStr=
		TimeStr=%A_Now%
	StringLeft Date,TimeStr,6	; YearMonth
	Date1 = %Date%
	Date1+= 31,D			; A day in next month
	StringLeft Date1,Date1,6	; YearNextmonth
	Date1-= %Date%,D		; Difference in days
	return	Date1
}

方案二

year := A_YEAR, month := A_MM
dat := year month "01"
dat += 70, Days
year := substr(dat,1,4), month := substr(dat,5,2)
dat := year month "01"
dat += -1, days
FormatTime, LastDay, %dat%, MMM dd yyyy
MsgBox % LastDay

方案三

q:: ;get last day of next month
vDate := DateAdd(SubStr(A_Now, 1, 6), 62, "Days")
vDate := DateAdd(SubStr(vDate, 1, 6), -1, "Days")
vDate := FormatTime(vDate, "MM/dd/yyyy")
MsgBox, % vDate
return

;commands as functions (AHK v2 functions for AHK v1) - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=37&t=29689

DateAdd(DateTime, Time, TimeUnits)
{
    EnvAdd DateTime, %Time%, %TimeUnits%
    return DateTime
}
DateDiff(DateTime1, DateTime2, TimeUnits)
{
    EnvSub DateTime1, %DateTime2%, %TimeUnits%
    return DateTime1
}
FormatTime(YYYYMMDDHH24MISS:="", Format:="")
{
    local OutputVar
    FormatTime OutputVar, %YYYYMMDDHH24MISS%, %Format%
    return OutputVar
}

 

打赏作者
本文为原创文章,未经同意禁止转载!!