获取当前日期时间
var now = new Date();
now.getYear();
now.getFullYear();
now.getMonth();
now.getDate();
now.getDay();
now.getTime();
now.getHours();
now.getMinutes();
now.getSeconds();
now.getMilliseconds();
now.toLocaleDateString();
now.toLocaleTimeString();
now.toLocaleString( );
//日期时间比较
function getBuXiu()
{
var Judge = true;
var stateCaption = getFormElement('_STATECAPTION');
if(stateCaption==null || stateCaption.value=="")
{
var QjStart = document.getElementsByName("QjStart")[0];
var QjEnd = document.getElementsByName("QjEnd")[0];
var QjDays = document.getElementsByName("QjDays")[0];
if((QjStart.value!="")&&(QjEnd.value!=""))
{
if((new Date(QjStart.value.replace(/-/g,"\/"))) >= (new Date(QjEnd.value.replace(/-/g,"\/"))))//日期时间比较及JS 正则表达式替换所有
{
Judge = false;
alert('开始时间大于或等于结束时间,请检查!');
}
else
{
QjDays.value=DateDiff(QjStart.value,QjEnd.value);//赋值
}
}
}
return Judge;
}
//日期时间格式转换
function DateDiff(sDate1, sDate2) {
var arrDate, objDate1, objDate2, intDays;
arrDate = sDate1.split('-');
objDate1 = new Date(arrDate[1] + '-' + arrDate[2] + '-' + arrDate[0]);
arrDate = sDate2.split('-');
objDate2 = new Date(arrDate[1] + '-' + arrDate[2] + '-' + arrDate[0]);
var hours=parseInt(Math.floor(objDate2 - objDate1)/(3600*1000));
if(hours==0)
intDays = 0;
else if(((hours/8)<1)&&((hours/24)<1))
intDays = Math.abs(hours/8);
else if(((hours/8)>=1)&&((hours/24)<=1))
intDays = 1;
else if(((hours/24)>1)&&((hours%24)<8)&&((hours%24)>0))
intDays = (parseInt((hours/24))+Math.abs((hours%24)/8));//转换成数字类型 及数的绝对值
else if(((hours/24)>1)&&((hours%24)>=8)&&((hours%24)<24))
intDays = (parseInt(hours/24)+1);
//intDays = parseInt(Math.abs(objDate1 - objDate2) / 1000 / 60 / 60 / 24);
return intDays;
}