显示30天有效日历

本文介绍如何制作一个35格、5行7列的日历,该日历设计用于展示30天的有效日期。内容包括前言、具体的实现方法和最终展示的效果。
摘要由CSDN通过智能技术生成

前言

实现35格 5行7列的日历,有效期为30天

实现

var dateObj = {
	'date' : new Date(),
	
	//判断闰年
	'is_leap' : function()
	{
		return (this.date.getFullYear() % 100 == 0 ? res = (this.date.getFullYear() % 400 == 0 ? 1 : 0) : res = (this.date.getFullYear() % 4 == 0 ? 1 : 0));
	},
	
	//本月第一天星期几
	'firstday' : function()
	{
		return new Date(this.date.getFullYear(), this.date.getMonth(), 1).getDay();
	},
	
	//本月天数
	'getDayNum' : function()
	{
		//获取年份
		var year = this.date.getFullYear();
		//获取当前月份
		var mouth = this.date.getMonth() + 1;
		//定义当月的天数;
		var days ;
		//当月份为二月时,根据闰年还是非闰年判断天数
		if(mouth == 2)
		{
			days= year % 4 == 0 ? 29 : 28;
		}
		else if(mouth == 1 || mouth == 3 || mouth == 5 || mouth == 7 || mouth == 8 || mouth == 10 || mouth == 12){
			//月份为:1,3,5,7,8,10,12 时,为大月.则天数为31;
			days= 31;
		}
		else
		{
			//其他月份,天数为:30.
			days= 30;
		}
		    
		//输出天数
		return days;
	},
	
	//最后一天星期几
	'lastday' : function(num)
	{
		var getMonth = this.monthNum()
		return new Date(this.date.getFullYear(), this.date.getMonth(), getMonth[num]).getDay();
	},
	
	//今天日期
	'getDates' : function()
	{
		return this.date.getDate();
	},
	
	//今天星期几
	'getWeek' : function()
	{
		return this.date.getDay();
	},
	
	//今天星期几
	'nowDayWeek' : function()
	{
		return new Date(this.date.getFullYear(), this.date.getMonth(), this.date.getDates).getDay();
	},
	
	//各月总天数
	'monthNum' : function()
	{
		return new Array(31, 28+this.is_leap(this.date.getFullYear()), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	},
	
	//计算所需行数
	'getTrNum' : function()
	{
		monthNum = this.monthNum();
		return Math.ceil((monthNum[this.date.getMonth()] + this.firstday()) / 7);
	},
	
	//上一个月
	'prevMonth ' : function()
	{
		if (this.tmp_month <= 0) 
		{
			this.tmp_month = 11; 
			this.tmp_year -=1;
		}
        else 
        {
        	this.tmp_month -= 1;
        }
		
        this.calendarShow();
        this.yearMonthShow();
        return false
	},
	
	//下一个月
	'nextMonth' : function()
	{
		if (this.tmp_month >= 11) 
		{
			this.tmp_month = 0; 
			this.tmp_year += 1;
		}
        else 
        {
        	this.tmp_month += 1;
        }
		
        this.calendarShow();
        this.yearMonthShow();
        re
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值