找回密码
 加入
搜索
查看: 1579|回复: 4

前一天的日期问题

[复制链接]
发表于 2009-3-24 21:46:57 | 显示全部楼层 |阅读模式
先看代码,想要输出的格式是20090323
#include <date.au3>
dim $mydate
dim $mytime

$newdate = _DateAdd("d",-1,_NowCalcDate())
MsgBox(0,"",$newdate)
_DateTimeSplit($newdate,$mydate,$mytime)
msgbox(0,"",$mydate[1] & $mydate[2] & $mydate[3])
最后输出的是2009323 月份那里少了个0,怎样解决?

[ 本帖最后由 风行者 于 2009-3-24 22:23 编辑 ]
发表于 2009-3-24 22:07:28 | 显示全部楼层
$mydate[2] 判断它的字符长度 如果长度为一 就用数组UDF函数修改它(在前面加0)
发表于 2009-3-24 22:09:56 | 显示全部楼层
#include <date.au3>
dim $mydate
dim $mytime

$newdate = _DateAdd("d",-1,_NowCalcDate())
MsgBox(0,"",$newdate)
_DateTimeSplit($newdate,$mydate,$mytime)
if $mydate[2]<10 then $mydate[2]="0"&$mydate[2]
msgbox(0,"",$mydate[1] & $mydate[2] & $mydate[3])

$mydate=StringSplit($newdate,"/")
msgbox(0,"",$mydate[1] & $mydate[2] & $mydate[3])
 楼主| 发表于 2009-3-24 22:20:59 | 显示全部楼层
噢,判断数字大小!谢谢上面两位的帮助

楼上提供了两种方法,很好又学到了

[ 本帖最后由 风行者 于 2009-3-24 22:22 编辑 ]
发表于 2009-3-26 11:41:18 | 显示全部楼层
StringFormat()
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-19 13:48 , Processed in 0.072196 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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