bootstrap中日期时间控件datatimepicker设置开始时间结束时间的用法:
$(id).datetimepicker({
language: 'zh-CN',
weekStart: 1,
startDate:‘2017-03-06’, //开始时间
endDate:‘2017-09-09’, //结束时间
todayBtn: 1,
autoclose: 1,
todayHighlight: 1,
startView: 2,
minView: 2,
forceParse: 0
});
可以把开始时间和结束时间设置成动态的,满足大多数日期时间的需求。
以下是对日期的一些常用操作方法,可以拿去直接使用。
jQuery.dateUtils = {
//判断月份
getMeetingMonthDate : function(){
//每月第一天
var firstDate = new Date();
firstDate.setDate(1);
//每月最后一天
var endDate = new Date(firstDate);
endDate.setMonth(firstDate.getMonth()+1);
endDate.setDate(0);
var month = {};
month.startDate = simpleFormatDate(firstDate);
month.endDate = simpleFormatDate(endDate);
return month;
},
//获得本季度的开端月份
getQuarterStartMonth : function (nowMonth){
var quarterStartMonth = 0;
if(nowMonth<3){
quarterStartMonth = 0;
}else if(2
}else if(5
}else if(nowMonth>8){
quarterStartMonth = 9;
}
return quarterStartMonth;
} ,
//获得本季度的开端日期
getQuarterStartDate : function (){
var now = new Date(); //当前日期
var nowYear = now.getYear(); //当前年
var nowMonth = now.getMonth(); //当前月
nowYear += (nowYear < 2000) ? 1900 : 0; //
var quarterStartDate = new Date(nowYear, this.getQuarterStartMonth(nowMonth), 1);
return simpleFormatDate(quarterStartDate);
} ,
//或的本季度的停止日期
getQuarterEndDate : function(){
var now = new Date(); //当前日期
var nowYear = now.getYear(); //当前年
var nowMonth = now.getMonth(); //当前月
nowYear += (nowYear < 2000) ? 1900 : 0; //
var quarterEndMonth = this.getQuarterStartMonth(nowMonth) + 2;
var quarterStartDate = new Date(nowYear, quarterEndMonth, this.getMonthDays(nowYear,quarterEndMonth));
return simpleFormatDate(quarterStartDate);
} ,
//获得某月的天数
getMonthDays : function(nowYear,myMonth){
var monthStartDate = new Date(nowYear, myMonth, 1);
var monthEndDate = new Date(nowYear, myMonth + 1, 1);
var days = (monthEndDate - monthStartDate)/(1000 * 60 * 60 * 24);
return days;
}
}
// 格式化时间 yyyy-MM-dd hh:mm:ss
function formatDate(timeStr) {
if (timeStr != null && timeStr != "") {
var datetime = new Date();
datetime.setTime(timeStr);
var year = datetime.getFullYear();
var month = datetime.getMonth() + 1 < 10 ? "0"
+ (datetime.getMonth() + 1) : datetime.getMonth() + 1;
var date = datetime.getDate() < 10 ? "0" + datetime.getDate()
: datetime.getDate();
var hour = datetime.getHours() < 10 ? "0" + datetime.getHours()
: datetime.getHours();
var minute = datetime.getMinutes() < 10 ? "0" + datetime.getMinutes()
: datetime.getMinutes();
var second = datetime.getSeconds() < 10 ? "0" + datetime.getSeconds()
: datetime.getSeconds();
timeStr = year + "-" + month + "-" + date + " " + hour + ":" + minute
+ ":" + second;
return timeStr;
}
return '';
}
// 格式化时间 yyyy-MM-dd
function simpleFormatDate(timeStr) {
if (timeStr != "" && timeStr != undefined) {
var datetime = new Date(timeStr);
// datetime.setTime(timeStr);
var year = datetime.getFullYear();
var month = datetime.getMonth() + 1 < 10 ? "0"
+ (datetime.getMonth() + 1) : datetime.getMonth() + 1;
var date = datetime.getDate() < 10 ? "0" + datetime.getDate()
: datetime.getDate();
timeStr = year + "-" + month + "-" + date;
return timeStr;
}else{
return "";
}
}