Jquery日期比较大小、日期格式化工具

//日期比较大小
function checkEndTime(startTime,endTime){
//    var startTime="2011-11-11 17:09";
    var start=new Date(startTime.replace("-", "/").replace("-", "/"));
//    var endTime="2011-11-11 17:09:08";;
    var end=new Date(endTime.replace("-", "/").replace("-", "/"));  
    if(end<start){  
        alert(false);
        return false;  
    }  
    alert(true);
    return true;  
} 



//日期格式化
Date.prototype.Format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //
        "H+": this.getHours(), //小时 
        "m+": this.getMinutes(), //
        "s+": this.getSeconds(), //
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
//日期格式化用法:
var time = new Date().Format("yyyy-MM-dd HH:mm:ss");

 

posted @ 2017-02-22 09:30  美材帮  阅读(483)  评论(0编辑  收藏  举报