Flex 日期操作之三(获取前天的日期)

在C#中获取前天的日期只需调用内部的方法即可

 //计算前天
string strYersterday = DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd");

在Flex中不知道有没有这种方法,自己用最原始的办法写了一个,没有判断是否有闰年的情况

//从时间格式里面提取昨天的年月日

private function getYearMonDay_Before(date:Date):String
{
var strYMD:String;
var strMon:String;
var strDay:String;
if(date == null)
{
strYMD = "2020/12/31";
}
else
{
if((date.getMonth()+1)<10)
{
strMon = "0" + (date.getMonth()+1).toString();
if((date.getDate()-2)<10&&(date.getDate()-2)>0)
strDay = "0" + (date.getDate()-2).toString();
else if((date.getDate() - 2) == 0)
{
switch(strMon)
{
case "01":
strDay = "31";
strMon = "12";
break;
case "02":
strDay = "31";
strMon = "01";
break;
case "03":
strDay = "28";
strMon = "02";
break;
case "04":
strDay = "31";
strMon = "03";
break;
case "05":
strDay ="30";
strMon = "04";
break;
case "06":
strDay = "31";
strMon = "05";
break;
case "07":
strDay = "30";
strMon = "06";
break;
case "08":
strDay = "31";
strMon = "07";
break;
case "09":
strDay = "31";
strMon = "08";
break;
case "10":
strDay = "30";
strMon = "09";
break;
case "11":
strDay = "31";
strMon ="10";
break;
case "12":
strDay ="30";
strMon = "11";
break;
}

}
else if (date.getDate()-2 < 0)
{
switch(strMon)
{
case "01":
strDay = "30";
strMon = "12";
break;
case "02":
strDay = "30";
strMon = "01";
break;
case "03":
strDay = "27";
strMon = "02";
break;
case "04":
strDay = "30";
strMon = "03";
break;
case "05":
strDay ="29";
strMon = "04";
break;
case "06":
strDay = "30";
strMon = "05";
break;
case "07":
strDay = "29";
strMon = "06";
break;
case "08":
strDay = "30";
strMon = "07";
break;
case "09":
strDay = "30";
strMon = "08";
break;
case "10":
strDay = "29";
strMon = "09";
break;
case "11":
strDay = "30";
strMon ="10";
break;
case "12":
strDay ="29";
strMon = "11";
break;
}
}
else
strDay = (date.getDate()-2).toString();
}

else
{
strMon = (date.getMonth()+1).toString();
if((date.getDate()-2)<10&&(date.getDate()-2)>0)
strDay = "0" + (date.getDate()-2).toString();
else if((date.getDate() - 2) == 0)
{
switch(strMon)
{
case "01":
strDay = "31";
strMon = "12";
break;
case "02":
strDay = "31";
strMon = "01";
break;
case "03":
strDay = "28";
strMon = "02";
break;
case "04":
strDay = "31";
strMon = "03";
break;
case "05":
strDay ="30";
strMon = "04";
break;
case "06":
strDay = "31";
strMon = "05";
break;
case "07":
strDay = "30";
strMon = "06";
break;
case "08":
strDay = "31";
strMon = "07";
break;
case "09":
strDay = "31";
strMon = "08";
break;
case "10":
strDay = "30";
strMon = "09";
break;
case "11":
strDay = "31";
strMon ="10";
break;
case "12":
strDay ="30";
strMon = "11";
break;
}

}
else if (date.getDate()-2 < 0)
{
switch(strMon)
{
case "01":
strDay = "30";
strMon = "12";
break;
case "02":
strDay = "30";
strMon = "01";
break;
case "03":
strDay = "27";
strMon = "02";
break;
case "04":
strDay = "30";
strMon = "03";
break;
case "05":
strDay ="29";
strMon = "04";
break;
case "06":
strDay = "30";
strMon = "05";
break;
case "07":
strDay = "29";
strMon = "06";
break;
case "08":
strDay = "30";
strMon = "07";
break;
case "09":
strDay = "30";
strMon = "08";
break;
case "10":
strDay = "29";
strMon = "09";
break;
case "11":
strDay = "30";
strMon ="10";
break;
case "12":
strDay ="29";
strMon = "11";
break;
}
}
else
strDay = (date.getDate()-2).toString();

}
strYMD = date.getFullYear().toString()+"/"+strMon+"/"+
strDay;
}
return strYMD;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值