加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex中计算某个月有多少天

发布时间:2020-12-15 04:24:34 所属栏目:百科 来源:网络整理
导读:/** *计算一个月中有多少天 * @author wangfeng * @date 2013年4月9日 15:47:58 */ private function dayCount(year:Number,month:Number):int{var result:int = 0;if(1==month || 3==month || 5==month|| 7==month || 8==month || 10==month || 12==month){


/**
			 *计算一个月中有多少天
			 * @author wangfeng
			 * @date 2013年4月9日 15:47:58 
			 */
			 private function dayCount(year:Number,month:Number):int
			{
				var result:int = 0;
				if(1==month || 3==month || 5==month|| 7==month || 8==month || 10==month || 12==month)
				{
						result = 31;
				}else if(4==month || 6==month || 9==month || 11==month)
				{
					result = 30;	
				}else if(2==month)
				{
					if((year % 4 == 0 && year %100 !=0) || year % 400 == 0)
					{
						result = 29;
					}else
					{
						result = 28;
					}
				}
				return result;	
			} 

在Flex中创建一个日期是本月最后一天的Date对象:

private var endDate:Date = new Date(new Date().getFullYear(),new Date().getMonth(),dayCount(new Date().getFullYear(),new Date().getMonth()+1));

注意,getMonth()方法返回的是0到11.0代表1月。2代表2月。依次类推。因此,在参数传递的时候,要在getMonth()上加1

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读