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
}

 

给TA捐赠
共{{data.count}}人
人已捐赠
其他

AHK实现Foxmail自动切换输入法

2018-3-5 19:19:59

其他

[定制]鬼魅订金专题

2018-3-7 14:45:03

3 条回复 A文章作者 M管理员
  1. zt7456

    根据大小月和闰年度算的吧

  2. 咦,有大神!

    作用是什么,能否详细解释下

    • 时间计算是在编程语言中一直都是一个非常有意思的区域,因为涉及到年月日度分秒,仅供大家学习参考!!

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索