(function(window){
function __Date() {
/*
返回时间格式统一为 -12-12
getDate:返回当前日期
getThisWeek:返回本周开始日期-结束日期
getThisMonth:返回本月开始日期-结束日期
getThisQuarter:返回本季度开始日期-结束日期
getThisYear: 返回本年开始日期-结束日期
*/
var currentData = new Date()
this.year = currentData.getFullYear()
this.month = currentData.getMonth() + 1
this.date = currentData.getDate()
this.day = currentData.getDay()
this.getDate = function(){
return this.formatDate()
}
this.getThisWeek= function(){
var oneDay = 24 * 60 * 60 * 1000
var startDay = this.formatDate(new Date() - (this.day * oneDay) )
var endDay = this.formatDate((6-this.day) * oneDay + +new Date())
return [startDay, endDay]
}
this.getThisMonth = function(){
var startDay = this.formatDate(this.year + '-' + this.month + '-' + '01')
var lastDay = new Date(this.year,this.month,0).getDate()
var endDay = this.formatDate(this.year + '-' + this.month + '-' + lastDay)
return [startDay, endDay]
}
this.getThisQuarter = function(){
var startMonth,endMonth;
var currentMonth = this.month
if(currentMonth >= 10){
startMonth = 10
endMonth = 12
}else if(currentMonth>=7){
startMonth = 7
endMonth = 9
}else if(currentMonth>=4){
startMonth = 4
endMonth = 6
}else{
startMonth = 1
endMonth = 3
}
var startDay = this.formatDate(this.year + '-' + startMonth + '-' + '01')
var lastDay = new Date(this.year,endMonth,0).getDate()
var endDay = this.formatDate(this.year + '-' + endMonth + '-' + lastDay)
return [startDay, endDay]
}
this.getThisYear = function(){
var startDay = this.formatDate(this.year + '-' + '01' + '-' + '01')
var lastDay = new Date(this.year,12,0).getDate()
var endDay = this.formatDate(this.year + '-' + '12' + '-' + lastDay)
return [startDay, endDay]
}
this.formatDate = function(date){
var currentData = date ? new Date(date) : new Date()
var year = currentData.getFullYear();
var month = currentData.getMonth()+1;
var date = currentData.getDate();
month = month < 10 ? '0' + month : month
date = date < 10 ? '0' + date : date
return year + '-' + month + '-' + date
}
}
window.__Date = new __Date()
})(window)
一键复制
编辑
Web IDE
原始数据
按行查看
历史