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

Ext.util.Format.date 时间格式的设置与转换的更多相关文章

  1. Ext.util.Format.date与Ext.Date.format区别, 转换时间戳

    在Extjs中装时间戳使用如下两种都可以: Ext.util.Format.date(time,'U'); Ext.Date.format(time, 'U'); 为了找到它们的区别,查看源代码,以E ...

  2. ExtJs之Ext.util.Format

    <!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...

  3. Extjs4 中date时间格式的问题

    在Grid中显示时间,后台传过来的是date格式的数据(PHP date('Y-m-d', time()),一般在Ext model中定义数据的类型和格式: {name:'birth', type:' ...

  4. 按照相应的格式获取系统时间并将其转化为SQL中匹配的(date)时间格式

    在获取时间时需要对时间格式进行设置,此时就需要用到SimpleDateFormat 类 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM ...

  5. Date时间格式的转换以及一些用法

    import java.util.Date; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.u ...

  6. jmeter中对于各类时间格式的设置

    最普通的设置为使用 函数助手中的__time, 设置好需要使用的类型,并设置接收参数即可 YMD = yyyyMMdd HMS = HHmmss YMDHMS = yyyyMMdd-HHmmss 第二 ...

  7. WordPress 博客文章时间格式the_time()设置

    国外设计的WordPress 主题里的文章的时间格式是类似“十一月 21, 2010”这种格式的,而中国人习惯的是年在前,月紧跟其后,日在末尾,所以看国外的就显得很别扭,但是我们可以通过修改WP时间代 ...

  8. new Date时间格式转换方法

    平时经常会使用到时间转换,组件库已经有很多组件可以自动生成时间类型了,但是底层的封装方法还是得有 获取当前时间 new Date()  或者自己拥有一个毫秒时间 方法如下 /** * title: 时 ...

  9. 关于javascript中时间格式和时间戳的转换

    当前时间获取的各种函数: var myDate = new Date();myDate.getYear();        //获取当前年份(2位),已经不推荐使用myDate.getFullYear ...

随机推荐

  1. 顺序表的C、C++实现

    一个线性表表实现,函数声明放在 line_list.h 头文件汇总,函数定义放在line_list.c 中,main.c 用来测试各个函数. 1.文件 line_list.h // line_list ...

  2. idea中添加类和方法注释以及codeCheck

    前言:在idea中我们添加类以及类的方法的注释很有必要,让其他人能够看懂这个类或者函数的作用是什么:为了在开发过程中检查自己的编程规范,可以通过codecheck工具进行自我检查和约束 一.在idea ...

  3. BZOJ 3170 松鼠聚会(切比雪夫距离转曼哈顿距离)

    题意 有N个小松鼠,它们的家用一个点x,y表示,两个点的距离定义为:点(x,y)和它周围的8个点即上下左右四个点和对角的四个点,距离为1.现在N个松鼠要走到一个松鼠家去,求走过的最短距离. 思路 题目 ...

  4. linux命令行打包、压缩及解压缩

    使用命令: tar 打包: tar -zcvf  目标文件 源文件或文件夹 目标文件为要打包成的文件的文件名, 打包后文件的 格式取决于目标文件的后缀名 单文件或文件夹打包 tar -zcvf ind ...

  5. MT【113】无中生有加一个减一个

    代数上可以这么解答:不妨设$x\le y$ 1)若$y-x\le\frac{1}{2},则|f(x)-f(y)|<\frac{1}{2}|x-y|\le\frac{1}{4}$ 2)若$y-x& ...

  6. 【刷题】BZOJ 3653 谈笑风生

    Description 设T 为一棵有根树,我们做如下的定义: ? 设a和b为T 中的两个不同节点.如果a是b的祖先,那么称"a比b不知道 高明到哪里去了". ? 设a 和 b 为 ...

  7. (转)Maven学习总结(五)——聚合与继承

    孤傲苍狼只为成功找方法,不为失败找借口! Maven学习总结(五)——聚合与继承 一.聚合 如果我们想一次构建多个项目模块,那我们就需要对多个项目模块进行聚合 1.1.聚合配置代码 1 <mod ...

  8. python 删除2天前后缀为.log的文件

    python脚本 删除2天前后缀为.log的文件 #!/usr/local/python/bin/python #-*-coding=utf8 -*- import time import os,sy ...

  9. vue 使用v-cloak让在页面加载时不显示{{}}花括号

    官方说法: 这个指令保持在元素上直到关联实例结束编译. 和 CSS 规则如 [v-cloak] { display: none } 一起用时,这个指令可以隐藏未编译的 Mustache 标签直到实例准 ...

  10. ngx_lua_API 指令详解(四)ngx.exec指令

    https://github.com/openresty/lua-nginx-module#ngxexec 参照:http://blog.csdn.net/weiyuefei/article/deta ...