javascript转换.net DateTime方法 (比如转换\/Date(1319878800000+0800)\/)
来源:互联网 发布:科学家自传 知乎 编辑:程序博客网 时间:2024/06/06 03:46
javascript端转换.net DateTime时间的代码
建议可以做成类的形式,不需要引入sencha-touch的js文件
var isDefined=function(v){ return typeof v !== 'undefined'; }; var useStrict = false; var parseDate=function(input, format, strict) { var p = parseFunctions; if (p[format] == null) { createParser(format); } return p[format](input, isDefined(strict) ? strict:useStrict); }; var parseFunctions={ "M{1}quot;: function(input, strict) { // note: the timezone offset is ignored since the M$ Ajax server sends // a UTC milliseconds-since-Unix-epoch value (negative values are allowed) var re = new RegExp('\\/Date\\(([-+])?(\\d+)(?:[+-]\\d{4})?\\)\\/'); var r = (input || '').match(re); return r ? new Date(((r[1] || '') + r[2]) * 1) : null; } }; var parseRegexes=[]; var createParser=function() { var code = [ "var dt, y, m, d, h, i, s, ms, o, z, zz, u, v,", "def = Date.defaults,", "results = String(input).match(Date.parseRegexes[{0}]);", // either null, or an array of matched strings "if(results){", "{1}", "if(u != null){", // i.e. unix time is defined "v = new Date(u * 1000);", // give top priority to UNIX time "}else{", // create Date object representing midnight of the current day; // this will provide us with our date defaults // (note: clearTime() handles Daylight Saving Time automatically) "dt = (new Date()).clearTime();", // date calculations (note: these calculations create a dependency on Ext.num()) "y = Ext.num(y, Ext.num(def.y, dt.getFullYear()));", "m = Ext.num(m, Ext.num(def.m - 1, dt.getMonth()));", "d = Ext.num(d, Ext.num(def.d, dt.getDate()));", // time calculations (note: these calculations create a dependency on Ext.num()) "h = Ext.num(h, Ext.num(def.h, dt.getHours()));", "i = Ext.num(i, Ext.num(def.i, dt.getMinutes()));", "s = Ext.num(s, Ext.num(def.s, dt.getSeconds()));", "ms = Ext.num(ms, Ext.num(def.ms, dt.getMilliseconds()));", "if(z >= 0 && y >= 0){", // both the year and zero-based day of year are defined and >= 0. // these 2 values alone provide sufficient info to create a full date object // create Date object representing January 1st for the given year "v = new Date(y, 0, 1, h, i, s, ms);", // then add day of year, checking for Date "rollover" if necessary "v = !strict? v : (strict === true && (z <= 364 || (v.isLeapYear() && z <= 365))? v.add(Date.DAY, z) : null);", "}else if(strict === true && !Date.isValid(y, m + 1, d, h, i, s, ms)){", // check for Date "rollover" "v = null;", // invalid date, so return null "}else{", // plain old Date object "v = new Date(y, m, d, h, i, s, ms);", "}", "}", "}", "if(v){", // favour UTC offset over GMT offset "if(zz != null){", // reset to UTC, then add offset "v = v.add(Date.SECOND, -v.getTimezoneOffset() * 60 - zz);", "}else if(o){", // reset to GMT, then add offset "v = v.add(Date.MINUTE, -v.getTimezoneOffset() + (sn == '+'? -1 : 1) * (hr * 60 + mn));", "}", "}", "return v;" ].join('\n'); return function(format) { var regexNum = Date.parseRegexes.length, currentGroup = 1, calc = [], regex = [], special = false, ch = "", i = 0, obj, last; for (; i < format.length; ++i) { ch = format.charAt(i); if (!special && ch == "\\") { special = true; } else if (special) { special = false; regex.push(Ext.util.Format.escape(ch)); } else { obj = $f(ch, currentGroup); currentGroup += obj.g; regex.push(obj.s); if (obj.g && obj.c) { if (obj.last) { last = obj; } else { calc.push(obj.c); } } } } if (last) { calc.push(last); } Date.parseRegexes[regexNum] = new RegExp("^" + regex.join('') + "{1}quot;); Date.parseFunctions[format] = new Function("input", "strict", xf(code, regexNum, calc.join(''))); }; }();function formatDate(dateString) {var ticks=parseDate(dateString, "M{1}quot;);d = new Date(ticks);return d.getDate() + "/"+ (d.getMonth() + 1) + "/" + d.getFullYear().toString().substring(2,4)};
- javascript转换.net DateTime方法 (比如转换\/Date(1319878800000+0800)\/)
- java Date 转换 mysql datetime
- String转换成Date 或Datetime
- Java Date和MySQL datetime数据类型转换
- Java Date和MySQL datetime数据类型转换
- 用JavaScript将long型数据转换成date型或datetime型
- javascript对象(date转换/正则表达式)
- C#DateTime的转换方法
- javascript double date相互转换
- 0039-javascript Date类型转换
- ASP.NET Ajax, JQuery & JSON Date Serialization,.net对象系列化为JSON的时候,DateTime类型的转换问题
- 将unixtime转换为.NET的DateTime
- asp.net 时间戳与datetime 转换
- Java中Date转换为Datetime、String与Date的相互转换
- DateTime Picker String value 转换 Date (Springmvc 注解@DateTimeFormat) 解决400请求无效问题
- java的Date类型转换成MySQL的DateTime类型
- dorado前台的datetime与oracle的date类型转换
- sql server 中将datetime类型转换为date,或者time
- Enum的一点点理解
- 求子数组之和最大值(包括循环)
- UIKeyboard键盘相关知识点-IOS开发
- 删除VS开发的Office插件
- 文件操作及常用函数整理
- javascript转换.net DateTime方法 (比如转换\/Date(1319878800000+0800)\/)
- Android学习笔记(一)
- crontab 定时备份oracle数据失败的处理方法
- 基于Widnows平台的7类常见的安全测试工具
- 音视频中的CBR,VBR,ABR
- 【Android Native Code开发系列】二 Ubuntu系统安装及软硬件问题
- struts2中转换器使用
- Eclipse插件
- JDK5新特性汇总