zoukankan      html  css  js  c++  java
  • js时间格式化(yy年MM月dd日 hh:mm)

    //时间格式化
    Date.prototype.format = function (format) {
        var o = {
            "M+": this.getMonth() + 1, //month
            "d+": this.getDate(), //day
            "h+": this.getHours(), //hour
            "m+": this.getMinutes(), //minute
            "s+": this.getSeconds(), //second
            "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
            "S": this.getMilliseconds() //millisecond
        }
    
        if (/(y+)/.test(format)) {
            format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        }
    
        for (var k in o) {
            if (new RegExp("(" + k + ")").test(format)) {
                format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
            }
        }
        return format;
    }
    
    function formatData(str, regexp) {
        // 转换日期格式
        str = str.replace(/-/g, '/'); // "2010/08/01";
        // 创建日期对象
        var date = new Date(str);
        return date.format(regexp);
    }
    
    formatData(data[i].create_time, 'yy年MM月dd日 hh:mm')
  • 相关阅读:
    宏------进阶

    公司用中会用到的iOS开源库和第三方组件(不断更新...)
    iOS 开发者旅途中的指南针
    国际化
    Block
    git简单使用教程
    XCode自带解析SAX解析
    GDataXMLNode解析XML
    Predicate
  • 原文地址:https://www.cnblogs.com/elves/p/3727293.html
Copyright © 2011-2022 走看看