@param timestamp: Pass in the timestamp, which must be a string of 10 or 13 bits * @param format: Date format, Y M D h M s * */var timestampToTime = function (timestamp,format) {var format_Arr = ['Y', 'M', 'D', 'h', 'm', 's']; timestamp = timestamp.toString().length === 13 ? Number(timestamp) : timestamp*1000; var data = new Date(timestamp); var Y = zerofill(data.getFullYear()), M = zerofill(data.getMonth()+1), D = zerofill(data.getDate()), h = zerofill(data.getHours()), m = zerofill(data.getMinutes()), s = zerofill(data.getMilliseconds()); var time_Arr = [Y, M, D, h, m, s]; time_Arr.forEach(function (value, index) { format = format.replace(format_Arr[index], value); }); return format; function zerofill (time) { var tiem_str = time.toString(); return tiem_str[1] ? tiem_str : '0' + tiem_str; }};Copy the code

References: www.jianshu.com/p/5d380b68c…