用js将从后台得到的13位时间戳(毫秒数)转换为想要的日期格式


function formatterTime(time, fmt) {

      if(!time){ return ''; } if(typeof(time) == "object" || typeof(time) == "OBJECT") { var z = { M: time.getMonth() + 1, d: time.getDate(), h: time.getHours(), m: time.getMinutes(), s: time.getSeconds() }; fmt = fmt.replace(/(M+|d+|h+|m+|s+)/g, function(v) { return ((v.length > 1 ? "0" : "") + eval('z.' + v.slice(-1))).slice(-2); }); return fmt.replace(/(y+)/g, function(v) { return time.getFullYear().toString().slice(-v.length); }); }else if(typeof(time) == "number"){ var TIME = new Date( time) ; var z = { M: TIME.getMonth() + 1, d: TIME.getDate(), h: TIME.getHours(), m: TIME.getMinutes(), s: TIME.getSeconds() }; fmt = fmt.replace(/(M+|d+|h+|m+|s+)/g, function(v) { return ((v.length > 1 ? "0" : "") + eval('z.' + v.slice(-1))).slice(-2); }); return fmt.replace(/(y+)/g, function(v) { return TIME.getFullYear().toString().slice(-v.length); }); } else return time; } formatterTime(1565780223000 ,"yyyy-MM-dd hh:mm:ss")


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM