当前第2页 返回上一页
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 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;
};
|
3、调用函数格式化:date.Format("yyyy-MM-dd hh:mm:ss");
这样就可以完成转换了,献给需要的朋友,这是前台格式化,那么我们是否能在转转换json之前进行一些操作,
得到我们想要的格式呢,也就是这个转换操作放在后台来做,有好的想法的读者可以交流。
推荐学习:《javascript高级教程》
以上就是JavaScript怎么将数字转换成时间的详细内容,更多文章请关注木庄网络博客!
返回前面的内容
相关阅读 >>
javascript知识点总结之 函数与事件
javascript如何判断对象是否数组
element-ui对话框可拖拽的功能如何实现?(附代码)
javascript document.write() 用法
javascript怎么判断是否是json格式
javascript怎么判断是否ie浏览器
javascript怎么移除属性
js怎么格式化日期
javascript如何进行数值交换
javascript怎么累加
更多相关阅读请进入《javascript》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » JavaScript怎么将数字转换成时间