js后台Date转显示格式的日期
2017-04-07 20:02
393 查看
//格式化时间 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.把上面的这段放在js文件中
2.new 一个date : var d= new Date();3.吧你自己从后台返回的日期set到date对象中,然后调用format:
d.setTime(data[i].createTime);
var timeStr = d.Format("yyyy-MM-dd");
$(time).text("[" + timeStr + "]");
time是自己的页面中id,
搞定了。。。
相关文章推荐
- 前台js获取到后台json数据,eval解析json后,日期(object)对象转换为date日期格式显示
- 以Json格式的后台Date对象显示在js中为object,object转成date字符串
- js转换Date日期格式
- js日期格式化,easy-ui,datebox得到日期改变格式
- 用js将从后台得到的时间戳(毫秒数)转换为想要的日期格式
- js转换Date日期格式
- js转换Date日期格式
- jqueryui的datepicker显示中文日期格式的设置
- 后台传来毫秒格式日期换成年月日时分秒显示在前台
- JS显示后台日期出现时差问题
- JS日期显示格式 yyyy-MM-dd hh:mm:ss
- js转换Date日期格式
- dateFormat.js ----jquery日期格式转换方法。
- JS实现span标签显示年月日日期格式
- JS会自动调用toString()方法来显示日期(即“Date对象的内容”)
- WPF -- 设置 DatePicker 的日期时间显示格式
- Js:消息弹出框、获取时间区间、时间格式、easyui datebox 自定义校验、表单数据转化json、控制两个日期不能只填一个
- js显示yyyy年mm日dd天 星期几 的格式日期
- js转换Date日期格式以及DateTime的一些总结
- js的date日期格式