js获得日期

// get the date string of today (1985/11/16)
function  getDateString() {
    
var myDate=new Date();
    
//get the full year(4 number,1970-????)
    var year=myDate.getFullYear();
    
//get the month(0-11,0 is Jan)
    var monthNum=myDate.getMonth();
    
var month;
    
if(monthNum<9){
        month
="0"+(monthNum+1);
    }
else{
        month
=monthNum+1;
    }

     
//get day(1-31)
    var day=myDate.getDate();
    
if(day<9){
        day
="0"+day;
    }

    
var today=year+"/"+month+"/"+day
    
return today;
}





// 验证文本框不能为空
function  checkNull() {
    
var   checkItems=new   Array( "date""timeFrom","timeTo");
    msgArray
={
        
"date":"createTimesheet.date",
        
"timeFrom":"createTimesheet.timeFrom",
        
"timeTo":"createTimesheet.timeTo"
    }
;
    
for(i in checkItems){
        
var item=document.getElementById(checkItems[i]);
        
var text=item.value;
        
if(text==null||text==""){
            alert(msgArray[checkItems[i]]
);
            
return false;
        }

    }

    
var temp=document.mainForm.date.value;
    
if(temp==null||temp==""){
        alert(
"<imartj2ee:Message application="oams.conf.oams" key="createTimesheet.date" />");
        
return false;
    }

    
return true;
}

// 校验2007/11/30 格式的日期,不正确的返回false
//
字符串替换  全局替换“/”chkDate=chkDate.replace(///g,"");
//
全局替换 a换成b chkDate=chkDate.replace(/a/g,"b");
//
替换一个a换成b chkDate=chkDate.replace("a","b");
function  checkSlashYyyymmdd(sDate) {
    
var chkDate=sDate;
    
if(chkDate.length !=10){
        
return false;
    }

    
if (chkDate.charAt(4!= "/"){
        
return false;
    }

    
if (chkDate.charAt(7!= "/"){
        
return false;
    }

    
var yyyy=chkDate.substring(0,4);
    
var mm=chkDate.substring(5,7);
    
if(isNaN(mm)==true){
        
return false;
    }

    mm
=parseInt(mm);
    
var dd=chkDate.substring(8,10);
    
var Dt;

    Dt
=new Date(yyyy,mm-1,dd);
    
if ((Dt.getFullYear()==yyyy) && (Dt.getMonth()+1==mm) && (Dt.getDate()==dd)){
        
return true;
    }

    
return false;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值