当前第2页 返回上一页
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
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;
}
|
调用:
1 2 3 | var time1 = new Date().Format( "yyyy-MM-dd" );
var time2 = new Date().Format( "yyyy-MM-dd hh:mm:ss" );
|
相关教程推荐:js教程
以上就是js如何实现时间的格式化的详细内容,更多文章请关注木庄网络博客!
返回前面的内容
相关阅读 >>
js与css的区别是什么
js控制输入框只允许输入小数
示例js 数组和对象的深拷贝操作
js怎么将字符串转为数组?
js中如何利用正则匹配多个全部数据
详细介绍js中的变量提升机制
js中行内style怎么写?
js中如何判断数据类型
js数组学习之清空全部元素的4种方法(代码详解)
ajax获取网页添加到div中的方法
更多相关阅读请进入《js》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » js如何实现时间的格式化