开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用微信号发送消息登录论坛

新人指南 邀请好友注册 - 我关注人的新帖 教你赚取精币 - 每日签到


求职/招聘- 论坛接单- 开发者大厅

论坛版规 总版规 - 建议/投诉 - 应聘版主 - 精华帖总集 积分说明 - 禁言标准 - 有奖举报

查看: 1126|回复: 2
收起左侧

一个mq语言的时间转换格式和大家分享一下

[复制链接]
发表于 2017-8-28 09:14:32 | 显示全部楼层 |阅读模式   北京市北京市
'添加指定时间日期
function add(jg,sl,datetime)
dim d,y,n,c,rq
rq=split(datetime,"/")
select case lcase(jg)
case "s"
d=sl
case "m"
d=sl*60
case "h"
d=sl*60*60
case "d"
d=sl*60*60*24
case "n"
y=int(rq(0)):n=int(rq(1)):d=0
While sl>12
if n<=2
if (y/4=int(y/4) and y/100<>int(y/100)) or (y/400=int(y/400) and y/100=int(y/100))
d=d+366*24*60*60
else
d=d+365*24*60*60
end if
elseif n>2
if ((y+1)/4=int((y+1)/4) and (y+1) /100<>int( (y+1) /100)) or ( (y+1) /400=int( (y+1) /400) and (y+1) /100=int( (y+1) /100))
d=d+366*24*60*60
else
d=d+365*24*60*60
end if
end if
sl=sl-12
y=y+1
Wend
for i=1 to sl+1
if n=1 or n=3 or n=5 or n=7 or n=8 or n=10 or n=12
c=31
elseif n=4 or n=6 or n=9 or n=11
c=30
elseif n=2
if (y/4=int(y/4) and y/100<>int(y/100) ) or (y/400=int(y/400) and y/100=int(y/100) )
c=29
else
c=28
end if
end if
if i<=sl
d=d+c*24*60*60
end if
if n=12
n=1
y=y+1
else
n=n+1
end if
next
if int(rq(2))>c
d=d-(int(rq(2))-c)*24*60*60
end if
case "y"
y=int(rq(0)):n=int(rq(1)):d=0
for sl
if n<=2
if (y/4=int(y/4) and y/100<>int(y/100)) or (y/400=int(y/400) and y/100=int(y/100))
d=d+366*24*60*60
else
d=d+365*24*60*60
end if
elseif n>2
if ((y+1)/4=int((y+1)/4) and (y+1)/100<>int((y+1)/100)) or ((1+y)/400=int((y+1)/400) and (1+y)/100=int((y+1)/100))
d=d+366*24*60*60
else
d=d+365*24*60*60
end if
end if
y=y+1
next
end select
add= ddate(int(dtime(datetime))+d)
end function

'两个时间差距
function diff(jg,dtime1,dtime2)
select case lcase(jg)
case "s"
diff=dtime(dtime2)-dtime(dtime1)
case "m"
diff=(dtime(dtime2)-dtime(dtime1))/60
case "h"
diff=(dtime(dtime2)-dtime(dtime1))/60/60
case "d"
diff=(dtime(dtime2)-dtime(dtime1))/60/60/24
end select
end function

'时间转换秒数
function dtime(datetime)
dim c,d
datetime=split(datetime,"/")
for i=0 to datetime(0)-1970-1
if ((1970+i)/4=int((1970+i)/4) and (1970+i)/100<>int((1970+i)/100)) or ((1970+i)/100=int((1970+i)/100) and (1970+i)/400=int((1970+i)/400) )
c=c+1
end if
next
d=(datetime(0)-1970)*365*24*60*60+c*24*60*60+datetime(3)*60*60+datetime(4)*60+datetime(5)
While int(datetime(1))>1
datetime(1)= datetime(1)-1
if datetime(1)=1 or datetime(1)=3 or datetime(1)=5 or datetime(1)=7 or datetime(1)=8 or datetime(1)=10 or datetime(1)=12
c=31
elseif datetime(1)=4 or datetime(1)=6 or datetime(1)=9 or datetime(1)=11
c=30
elseif datetime(1)=2 and (datetime(0)/4=int(datetime(0)/4) and datetime(0)/100<>int(datetime(0)/100)) or ( datetime(0)/400=int(datetime(0)/400) and datetime(0)/100=int(datetime(0)/100) )
c=29
else
c=28
end if
datetime(2)=datetime(2)+c
Wend
datetime(2)= datetime(2)-1
dtime=d+datetime(2)*24*60*60-8*60*60
end function

'秒转换日期时间
function ddate(time)
dim y,d,h,m,s,c,n
c=0
time=int(time)+8*60*60
y=int(time/(365*24*60*60))
for i=0 to int(y)-1
if ((1970+i)/4=int((1970+i)/4) and (1970+i)/100<>int((1970+i)/100)) or ((1970+i)/100=int((1970+i)/100) and (1970+i)/400=int((1970+i)/400) )
c=c+1
end if
next
y=y-int(c/365):c=0
for i=0 to int(y)-1
if ((1970+i)/4=int((1970+i)/4) and (1970+i)/100<>int((1970+i)/100)) or ((1970+i)/100=int((1970+i)/100) and (1970+i)/400=int((1970+i)/400) )
c=c+1
end if
next
c= 60*60*24*c
d=int((time-c-60*60*24*365*int(y))/60/60/24)
h=int((time-c-60*60*24*365*int(y)-int(d)*24*60*60)/60/60)
m=int((time-c-60*60*24*365*int(y)-int(d)*24*60*60-int(h)*60*60)/60)
s=(time-c-60*60*24*365*int(y)-int(d)*24*60*60-int(h)*60*60-int(m)*60)
c=31:n=1
While d>=c
d=d-c
n=n+1
if n=1 or n=3 or n=5 or n=7 or n=8 or n=10 or n=12
c=31
elseif n=4 or n=6 or n=9 or n=11
c=30
elseif n=2 and ((1970+y)/4=int((1970+y)/4) and (1970+y)/100<>int((1970+y)/100)) or ((1970+y)/100=int((1970+y)/100) and (1970+y)/400=int((1970+y)/400) )
c=29
else
c=28
end if
Wend
d=d+1
n=String(2-len(n),"0")&n
d= String(2-len(d),"0")&d
h= String(2-len(h),"0")&h
m= String(2-len(m),"0")&m
s= String(2-len(s),"0")&s
ddate= int(y+1970)&"/"&n&"/"&d&"/"&h&"/"&m&"/"&s
end function


签到天数: 1 天

发表于 2017-9-4 21:33:16 | 显示全部楼层   湖北省黄石市
学习了学习了学习了学习了学习了
回复 支持 反对

使用道具 举报

发表于 2017-9-2 22:24:17 | 显示全部楼层   河北省石家庄市
学习了学习了学习了学习了学习了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 致发广告者

发布主题 收藏帖子 返回列表

sitemap| 易语言源码| 易语言教程| 易语言论坛| 诚聘英才| 易语言模块| 手机版| 广告投放| 精易论坛
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
论坛帖子内容仅用于技术交流学习和研究的目的,严禁用于非法目的,否则造成一切后果自负!如帖子内容侵害到你的权益,请联系我们!
防范网络诈骗,远离网络犯罪 违法和不良信息举报电话0663-3422125,QQ: 800073686,邮箱:800073686@b.qq.com
Powered by Discuz! X3.4 揭阳市揭东区精易科技有限公司 ( 粤ICP备12094385号-1) 粤公网安备 44522102000125 增值电信业务经营许可证 粤B2-20192173

快速回复 返回顶部 返回列表