ITeye博客

js简版 TimeUtil

BBjava · 2013-12-29 21:10 · jquery · Web前端 · Markdown

原地址为:http://bbjava.iteye.com/admin/blogs/1997125。



var TimeUtil = function(){
	var date = new Date();
	var yyyy = date.getFullYear();
	var MM = date.getMonth()+1;
	var dd = date.getDate();
	var HH = date.getHours();
	var mm = date.getMinutes();
	function getTime(){
		return yyyy+"-"+MM+"-"+dd+" "+HH+":00:00";
	}
	
	function getLastHour(){
		date.setHours(date.getHours(), 0, 0, 0);
		HH = date.getHours();
		return yyyy+"-"+MM+"-"+dd+" "+HH+":00:00";
	}

	function getLastDate(){
		date.setDate(date.getDate()-1);
		dd = date.getDate();
		return yyyy+"-"+MM+"-"+(dd-1)+" "+HH+":00:00";
	}
	
	function getLastDay(){
		date.setDate(date.getDate()-1);
		dd = date.getDate();
		return yyyy+"-"+MM+"-"+dd;
	}
	
	function getToday(){
		return yyyy+"-"+MM+"-"+(dd);
	}
	
	return {
		getLastHour:function(){
			return getLastHour();
		},
		getTime:function(){
			return getTime();
		},
		getLastDate:function(){
			return getLastDate();
		},
		getLastDay:function(){
			return getLastDay();
		}
		
	};
	
};

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。