zoukankan      html  css  js  c++  java
  • Ext.util.Format.date 时间格式的设置与转换

    Ext.util.Format.date

    1. var d = new Date(value.time);  
    2. var s = Ext.util.Format.date(d, 'Y-m-d H:m:s');  
    3. return s;  
    在Chrome的Develop Tools中断点调试,发现这些变量的值为:
    value.time: 1396257528000
    d: Mon Mar 31 2014 17:18:48 GMT+0800 (中国标准时间)
    s: "2014-03-31 17:03:48"
    年月日时分秒中,只有分钟不对,硬生生的差了15分钟,汗!
    单步跟踪进去,发现是Extjs的源码(VM13060)里有问题,竟然用月份代替了分钟:
    1. (function() {  
    2.     var Ext = window.ExtBox1;  
    3.     return Ext.String.leftPad(this.getFullYear(), 4, '0') + '-' + Ext.String.leftPad(this.getMonth() + 1, 2, '0') + '-'   
    4.         + Ext.String.leftPad(this.getDate(), 2, '0') + ' ' + Ext.String.leftPad(this.getHours(), 2, '0') + ':'   
    5.         + Ext.String.leftPad(this.getMonth() + 1, 2, '0') + ':' + Ext.String.leftPad(this.getSeconds(), 2, '0')  
    6. })  
    仔细一想,发现是分钟(minute)与月份(month)搞错了,分钟应该用i而不是m
    1. Ext.util.Format.date(d, 'Y-m-d H:i:s');  
    Extjs的源码里有各种格式的功能的:
    1. formatCodes : {  
    2.     d: "Ext.String.leftPad(this.getDate(), 2, '0')",  
    3.     D: "Ext.Date.getShortDayName(this.getDay())",   
    4.     j: "this.getDate()",  
    5.     l: "Ext.Date.dayNames[this.getDay()]",  
    6.     N: "(this.getDay() ? this.getDay() : 7)",  
    7.     S: "Ext.Date.getSuffix(this)",  
    8.     w: "this.getDay()",  
    9.     z: "Ext.Date.getDayOfYear(this)",  
    10.     W: "Ext.String.leftPad(Ext.Date.getWeekOfYear(this), 2, '0')",  
    11.     F: "Ext.Date.monthNames[this.getMonth()]",  
    12.     m: "Ext.String.leftPad(this.getMonth() + 1, 2, '0')",  
    13.     M: "Ext.Date.getShortMonthName(this.getMonth())",   
    14.     n: "(this.getMonth() + 1)",  
    15.     t: "Ext.Date.getDaysInMonth(this)",  
    16.     L: "(Ext.Date.isLeapYear(this) ? 1 : 0)",  
    17.     o: "(this.getFullYear() + (Ext.Date.getWeekOfYear(this) == 1 && this.getMonth() > 0 ? +1 : "  
    18. "(Ext.Date.getWeekOfYear(this) >= 52 && this.getMonth() < 11 ? -1 : 0)))",  
    19.     Y: "Ext.String.leftPad(this.getFullYear(), 4, '0')",  
    20.     y: "('' + this.getFullYear()).substring(2, 4)",  
    21.     a: "(this.getHours() < 12 ? 'am' : 'pm')",  
    22.     A: "(this.getHours() < 12 ? 'AM' : 'PM')",  
    23.     g: "((this.getHours() % 12) ? this.getHours() % 12 : 12)",  
    24.     G: "this.getHours()",  
    25.     h: "Ext.String.leftPad((this.getHours() % 12) ? this.getHours() % 12 : 12, 2, '0')",  
    26.     H: "Ext.String.leftPad(this.getHours(), 2, '0')",  
    27.     i: "Ext.String.leftPad(this.getMinutes(), 2, '0')",  
    28.     s: "Ext.String.leftPad(this.getSeconds(), 2, '0')",  
    29.     u: "Ext.String.leftPad(this.getMilliseconds(), 3, '0')",  
    30.     O: "Ext.Date.getGMTOffset(this)",  
    31.     P: "Ext.Date.getGMTOffset(this, true)",  
    32.     T: "Ext.Date.getTimezone(this)",  
    33.     Z: "(this.getTimezoneOffset() * -60)",  
    34.     c: function() {   
    35. for (var c = "Y-m-dTH:i:sP", code = [], i = 0, l = c.length; i < l; ++i) {  
    36. var e = c.charAt(i);  
    37.             code.push(e == "T" ? "'T'" : utilDate.getFormatCode(e));   
    38.         }  
    39. return code.join(" + ");  
    40.     },          
    41.     U: "Math.round(this.getTime() / 1000)"  
    42. },  

    原文链接:https://blog.csdn.net/gaojinshan/article/details/22683777

  • 相关阅读:
    Oracle 10gR2 Dataguard搭建(非duplicate方式)
    Linux scp 设置nohup后台运行
    Linux平台 Oracle 10gR2(10.2.0.5)RAC安装 Part3:db安装和升级
    Linux平台 Oracle 10gR2(10.2.0.5)RAC安装 Part2:clusterware安装和升级
    eclipse debug模式下总是自动跳到ThreadPoolExecutor.java类
    eclipse maven build、maven clean、maven install和maven test的区别 精析
    燕麦工作室第一卷:火力地堡高清下载
    java 泛型 精析
    任志强商学课:用企业家的思维理解商业 下载
    NodeJs编写小爬虫
  • 原文地址:https://www.cnblogs.com/1175429393wljblog/p/9177923.html
Copyright © 2011-2022 走看看