//从MySQL数据库中 时间格式的字段显示值:2017-08-08 17:27:47 //获取数据对象,然后将数据对象的值,显示出来:'Oct 10, 2017 9:26:16 AM' 即 data[i].createtime='Oct 10, 2017 9:26:16 AM'; //先将中国标准时间格式字符串转换为日期类型 var createtime=new Date(data[i].createtime); 调用一下函数即可: formatDate(createtime); 最终显示为:2017-08-08 17:27:47 function formatTen(num) { return num > 9 ? (num + "") : ("0" + num); } function formatDate(date) { var year = date.getFullYear(); var month = date.getMonth() + 1; var day = date.getDate(); var hour = date.getHours(); var minute = date.getMinutes(); var second = date.getSeconds(); return year + "-" + formatTen(month) + "-" + formatTen(day)+" "+hour+":"+minute+":"+second; }
js将中国标准时间转换成指定格式的时间
猜你喜欢
转载自451640893.iteye.com/blog/2397072
今日推荐
周排行