ie 与 Chrome 时间格式化问题.
ie 与 Chrome 时间格式化通用:
new Date(res[i].Time.replaceAll("-", "/")).format("yyyy-MM-dd")
replaceAll, format是扩展方法
/*
所以可以用以下几种方式.:
string.replace(new RegExp(strSearch, 'g'), strReplace);
string:字符串表达式包含要替代的子字符串。
strSearch:被搜索的子字符串。
strReplace:用于替换的子字符串。
*/
String.prototype.replaceAll = function(strSearch, strReplace, ignoreCase) {
if (!RegExp.prototype.isPrototypeOf(strSearch)) {
return this.replace(new RegExp(strSearch, (ignoreCase ? "gi" : "g")), strReplace);
} else {
return this.replace(strSearch, strReplace);
}
}
/**
* 将时间转换成固定格式输出
* new Date().toFormat('yyyy-MM-dd HH:mm:ss');
* new Date().toFormat('yyyy/MM/dd hh:mm:ss');
* 只支持关键字(yyyy、MM、dd、HH、hh、mm、ss)HH:表示24小时,hh表示12小时
*/
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;
}
ie 与 Chrome 时间格式化问题.的更多相关文章
- 国际化相对时间格式化API:Intl.RelativeTimeFormat
原文:The Intl.RelativeTimeFormat API 作者:Mathias Bynens(@mathias) 现代 Web 应用程序通常使用"昨天","4 ...
- strftime 日期时间格式化
strftime() 函数根据区域设置格式化本地时间/日期,函数的功能将时间格式化,或者说格式化一个时间字符串. size_t strftime(char *strDest,size_t maxsiz ...
- javascript 时间格式化
添加扩展 //时间格式化扩展Date.prototype.format = function(format){ var o = { "M+" : this.getMonth()+1 ...
- js时间格式化
const formatDate = timestamp => { const date = new Date(timestamp); const m = date.getMonth() + 1 ...
- js对特殊字符转义、时间格式化、获取URL参数
/*特殊字符转义*/ function replace_html(str) { var str = str.toString().replace(/&/g, "&" ...
- 特殊字符转义&时间格式化&获取URL参数
/*特殊字符转义*/ function htmlspecialchars (str) { var str = str.toString().replace(/&/g, "&& ...
- 【AspNetCore】【WebApi】扩展Webapi中的RouteConstraint中,让DateTime类型,支持时间格式化(DateTimeFormat)
扩展Webapi中的RouteConstraint中,让DateTime类型,支持时间格式化(DateTimeFormat) 一.背景 大家在使用WebApi时,会用到DateTime为参数,类似于这 ...
- EasyUI Datagrid Datetime(EasyUI DataGrid 时间格式化)
EasyUI DataGrid 时间格式化 方法一: var Common = { //EasyUI用DataGrid用日期格式化 TimeFormatter: function (value, re ...
- js Date 时间格式化的扩展
js Date 时间格式化的扩展: Date.prototype.format = function (fmt) { var o = { , //月 "d+": this.getD ...
随机推荐
- ViewPager中GridView问题
GridView 嵌套在ViewPager中问题. 1. GridView属性设置无法显示. 正常显示方式 <GridView android:padding="8dip" ...
- 一元三次方程 (codevs 1038)题解
[问题描述] 有形如:ax3+bx2+cx+d=0这样的一个一元三次方程.给出该方程中各项的系数(a,b,c,d均为实数),并约定该方程存在三个不同实根(根的范围在-100至100之间),且根与根之差 ...
- IL中的栈和闪电的Owin推荐
最近几天有幸得到闪电大哥的指点,了解了EMIT和IL中的一些指令.虽然有高射炮打蚊子的说法,但是我相信“二八定律”,80%的功能可以用20%的技术解决,20%的功能只能用80%的技术解决.大哥的博客: ...
- struts2 s:if标签以及 #,%{},%{#}的使用方法等在资料整理
<s:if>判断字符串的问题: 1.判断单个字符:<s:if test="#session.user.username=='c'"> 这样是从session ...
- python中读取配置文件ConfigParser
在程序中使用配置文件来灵活的配置一些参数是一件很常见的事情,配置文件的解析并不复杂,在python里更是如此,在官方发布的库中就包含有做这件事情的库,那就是ConfigParser,这里简单的做一些介 ...
- ruby 笔记
symbol 不能有- 'data-turbolinks-track' => true stop rails –s kill -INT $(cat tmp/pids/server.pid) cl ...
- i++与++i的误解
javap -c xx.class {i=0i=i++}0: bipush 02: istore_1 stack ->var13: iload_1 var1->stack4: iinc 1 ...
- 【FAQ】【JSP】HTTP Status 500 - Summary(问题排查时候应该仔细分析所有的错误打印说明)
Question 1.HTTP Status 500 - Unable to compile class for JSP:'***' cannot be resolved to a type 原因分析 ...
- JavaScript 字符串处理详解【转自:http://www.cnblogs.com/mondLei/p/4096855.html】
一.创建字符串 创建一个字符串,将一组字符串用引号包起来,将其赋值给一个字符串变量. var JsStr="Hello,JavaScript String!"; 二.字 ...
- python中的lambda
lambda表达式返回一个函数对象 例子: func = lambda x,y:x+y func相当于下面这个函数 def func(x,y): return x+y 注意def是语句而lambda是 ...