当前位置: 移动技术网 > IT编程>开发语言>JavaScript > js得到规范的时间格式函数,并调用

js得到规范的时间格式函数,并调用

2019年01月14日  | 移动技术网IT编程  | 我要评论
1.js得到规范的时间格式函数 Date.prototype.format = function(fmt) { var o = { "M+" : this.getMonth()+1, //月份 "d+" : this.getDate(), //日 "h+" : this.getHours(), // ...

1.js得到规范的时间格式函数

date.prototype.format = function(fmt) {

     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;

2.调用时间函数

nowdate=now.format("yyyy-mm-dd hh:mm:ss");

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网