[安卓/IOS按键精灵源码分享] 日期时间格式化函数(二),返回经过指定时间后所处日期时间

//函数功能:返回一个从当前系统时间算起经过指定时间长度后的日期时间字符串
//intH(小时数)、intM(分钟数)、intS(秒数):由调用者指定的时间长度,intH、intM、intS总时间跨度限于28天内
//strFormt:由调用者指定返回格式,格式:YYYY、YY、MM、DD、hh、mm、ss 任意组合(获取日期或时间部分的一项或多项),大小写敏感
//例:TracePrint LsGetNextTime(48,53,20,"YYYY年MM月DD日") //返回经过48小时53分钟20秒后所处的日期
//例:TracePrint LsGetNextTime(10,5,0,"YYYY年MM月DD日,hh时") //返回经过10小时5分钟后所处的日期和24小时格式的时
//例:TracePrint LsGetNextTime(36,120,12000,"YYYY年MM月DD日,hh时mm分ss秒") 返回经过36小时120分钟12000秒后所处的年月日,时分秒(24小时格式)
//结合本人之前分享的 LsDateTime()函数,即能轻松实现定时时间判断,而不是延时时间判断。

LsDateTime()函数见另外一篇文章
Function LsGetNextTime(intH,intM,intS,strFormat)
Dim arrMth,intMth2,intLeapYear,intInterval,varGetTime,intNow,intNextTime,varGetDate,intHH,intMM,intSS,intDays,intMons,intYears
LsGetNextTime=""
If strFormat="?" Then
TracePrint "例:TracePrint LsGetNextTime(36,120,12000," & chr(34) & "YYYY年MM月DD日,hh时mm分ss秒" & chr(34) & ") 参数说明:从左往右依次:小时数、分种数、秒数、返回格式,注意:大小写敏感"
End If
//取得当前的日期
varGetDate=Split(Date(),"/")
//年月日强制转换为数值
varGetDate(0)=CInt(varGetDate(0))
varGetDate(1)=CInt(varGetDate(1))
varGetDate(2)=CInt(varGetDate(2))
//生成本年各月份天数
//公历闰年:可被4整除且不能被100整除的年份
If (varGetDate(0) mod 4=0) and (varGetDate(0) mod 100>0) then
arrMth=Array(0,31,29,31,30,31,30,31,31,30,31,30,31)
Else
arrMth=Array(0,31,28,31,30,31,30,31,31,30,31,30,31)
End If

//1.转换为以秒为单位的时间长度
If IsNumeric(intH) and IsNumeric(intM) and IsNumeric(intS) Then
intInterval=(intH*60*60)+(intM*60)+intS
If intInterval>2419200 Then
TracePrint "错误:不支持时间跨度大于28天(即总时长2419200秒)的计算"
Exit Function
End If
Else
TracePrint "错误:intH,intM,intS都必须为数值"
Exit Function
End If
//2.系统时间转换为秒并与时间长度相加
varGetTime=split(now()," ")
varGetTime=split(varGetTime(3),":")
intNow=cint(varGetTime(0))*60*60+cint(varGetTime(1))*60+cint(varGetTime(2))
intNextTime=intNow+intInterval
//3.获得下一个时间表达式的各项
//3.1获得秒
intSS=intNextTime mod 60
//3.2获得分
intMM=int((intNextTime mod 3600)/60)
//3.3获得下一时间的时
intHH=int(intNextTime/3600)
intHH=intHH mod 24
//3.4获得下一时间的日
intDays=int(intInterval/(3600*24))+varGetDate(2)
If intDays>arrMth(varGetDate(1)) Then //当前日期加经过天数大于本月天数,则计算出下一月所处的日
intDays=intDays mod arrMth(varGetDate(1))
intMons=1 //月份+1
Else
intMons=0
End If
//3.5获得下一时间的月份
If varGetDate(1)=12 and intMons>0 Then
//若当前月份为12月,且下一日发生在下一月则月、年=+1,月份转至1月
intMons=1
intYears=1
Else
intMons=varGetDate(1)+intMons
intYears=0
End If
//3.6获得下一时间的年份
intYears=varGetDate(0)+intYears
//4.按指定格式处理返回值
strFormat=Replace(strFormat,"YYYY",cstr(intYears))
strFormat=Replace(strFormat,"YY",right(cstr(intYears),2))
strFormat=Replace(strFormat,"MM",cstr(intMons))
strFormat=Replace(strFormat,"DD",cstr(intDays))
strFormat=Replace(strFormat,"hh",cstr(intHH))
strFormat=Replace(strFormat,"mm",cstr(intMM))
strFormat=Replace(strFormat,"ss",cstr(intSS))
LsGetNextTime=strFormat
End Function

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值