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. js弹出层学习

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  2. Java之扫描目录,修改文件内容

    扫描目录下文件,修改文件中指定内容 package org.utils.tools.fileoper; import java.io.*; import java.util.ArrayList; im ...

  3. js new关键字

    实现new 关键字只需4步 1. 声明一个对象: 2. 把这个对象的__proto__ 指向构造函数的 prototype; 3. 以构造函数为上下文执行这个对象: 4. 返回这个对象. 简洁的代码示 ...

  4. Duplicate spring bean id

    问题背景:从本地调用服务器的dubbo接口进行测试 实现思路:基于IDEA+Spring+maven+Dubbo搭建测试项目,从本地直接调用   具体实现思路可参考博客:https://www.cnb ...

  5. 小菜菜mysql练习解读分析2——查询存在" 01 "课程但可能不存在" 02 "课程的情况(不存在时显示为 null )

    “查询存在" 01 "课程但可能不存在" 02 "课程的情况(不存在时显示为 null )” ——翻译为:课程表里面,存在01的信息,未必满足有02的课程情况 ...

  6. Codeforces Round #530 Div. 1 自闭记

    A:显然应该让未确定的大小尽量大.不知道写了啥就wa了一发. #include<iostream> #include<cstdio> #include<cmath> ...

  7. Triangle Counting UVA - 11401(递推)

    大白书讲的很好.. #include <iostream> #include <cstring> using namespace std; typedef long long ...

  8. 前端学习 -- Html&Css -- 相对定位 绝对定位 固定定位

    相对定位 - 定位指的就是将指定的元素摆放到页面的任意位置,通过定位可以任意的摆放元素. - 通过position属性来设置元素的定位. -可选值: static:默认值,元素没有开启定位: rela ...

  9. JDK自带线程池介绍及使用环境

    1.newFixedThreadPool创建一个指定工作线程数量的线程池.每当提交一个任务就创建一个工作线程,如果工作线程数量达到线程池初始的最大数,则将提交的任务存入到池队列中. 2.newCach ...

  10. 21天实战caffe笔记_第三天

    1 深度学习工具汇总 (1)  caffe : 由BVLC开发的基于C++/CUDA/Python实现的卷积神经网络,提供了面向命令行.Matlab和Python的绑定接口.特性如下: A 实现了前馈 ...