[FUNC]AHK有没有日期运算?比如,20-DEC-2018 减2天

AHK有没有日期运算?比如,20-DEC-2018 减2天  

回答网友提问如下:

;~功能:计算日期减法
;~作者:sunwind 1576157
;~最新版地址:https://blog.csdn.net/liuyukuan/article/details/84385196
 
;~ AHK有没有日期运算?比如,20-DEC-2018 减3天  
MsgBox % 日期减法("20-DEC-2018",3)
;输出  17-DEC-2018
Return
日期减法(str,int)
{
     VarContainingTimestamp:=ConvertDate(str)
     EnvAdd, VarContainingTimestamp, -%int%, days.
     FormatTime, VarContainingTimestamp, %VarContainingTimestamp%  L0x0409,dd-MMM-yyyy
     ;L0x0409是LCID, 参考 http://www.cnblogs.com/del/archive/2009/05/21/1486645.html
     VarContainingTimestamp:=Format("{:U}", VarContainingTimestamp)
     return VarContainingTimestamp
}



ConvertDate( Date ) {
  Static Jan:="01", Feb:="02", Mar:="03", Apr:="04", May:="05", Jun:="06", Jul:="07"
       , Aug:="08", Sep:="09", Oct:="10", Nov:="11", Dec:="12"
  StringSplit, D, Date, "-"
Return d3 monthnumber(d2) d1
}


monthnumber(imput) { 
	;~ 注意下面的字串构造很有技巧,每个单词9个字母。用空格补空位。
   Static Months := "January  February March    April    May      June     July     August   SeptemberOctober  November  December" 
   Return SubStr(0 . (InStr(Months,imput)+8)//9, -1) 
}

 

你可能感兴趣的:(AutoHotkey,热键,函数库,效率)