JS日期+1格式化成yyyy-MM-dd
2016-01-05 14:09
711 查看
[javascript] view
plaincopy
Date.prototype.Format = function (fmt) {
var o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}
调用:
[javascript] view
plaincopy
var myDate = new Date().Format("yyyy-MM-dd"); <span style="font-family: Arial, Helvetica, sans-serif;">//今天</span>
var myDate = new Date((new Date() / 1000 + 86400) * 1000).Format("yyyy-MM-dd"); //明天
plaincopy
Date.prototype.Format = function (fmt) {
var o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}
调用:
[javascript] view
plaincopy
var myDate = new Date().Format("yyyy-MM-dd"); <span style="font-family: Arial, Helvetica, sans-serif;">//今天</span>
var myDate = new Date((new Date() / 1000 + 86400) * 1000).Format("yyyy-MM-dd"); //明天
相关文章推荐
- JavaScript拾漏之变量作用域
- js 字符串换行,指定长度,指定符号
- 在jsp页面中使用list列表来传递信息到action
- JavaScript_在什么位置编写 JS 代码
- js代码的执行顺序
- js中substr,substring,indexOf,lastIndexOf,split 的用法
- js中控制时间
- js e.target
- extjs获取选中列表!
- DOM LEVEL 1 中的那些事儿[总结篇-上]
- JSON-C 的安装与使用
- 抓取Js动态生成数据且以滚动页面方式分页的网页
- js常用字符串操作方法
- javascript 如何避免属性访问错误
- js获取名字为XX的标签
- js 原生获取Class元素
- js获取页面的可视宽高度,占位宽高度,获取元素左上角相对页面左上角的位置,元素左上角相对可是区域的位置,元素是否存在于页面可视范围内
- Stack Overflow requires external JavaScript from another domain, which is blocked or failed to load
- webpy模版中写JS代码的陷阱
- js 浮点数加减问题