1.时间戳转换
1 //时间戳(有Date和无Date的都可)转换为日期 “2016年5月30日 10:29:30 2016-05-20 09:11” 2 function TimeConversion(timeStamp,type) { 3 if (timeStamp) { 4 if (timeStamp.indexOf('Date') > -1) { 5 var dtime = timeStamp.substring(6, timeStamp.length - 2); 6 var newDate = new Date(); 7 newDate.setTime(dtime); 8 var year = newDate.getFullYear(); 9 var month = newDate.getMonth() + 1; 10 var data = newDate.getDate(); 11 var hour = '0' + newDate.getHours(); 12 hour = hour.substring(hour.length - 2) 13 var minute = '0' + newDate.getMinutes(); 14 minute = minute.substring(minute.length - 2) 15 var second = '0' + newDate.getSeconds(); 16 second = second.substring(second.length - 2) 17 var s = ""; 18 if (type && type == 1) { 19 s = year + "-" + month + "-" + data + " " + hour + ":" + minute; 20 } 21 else { 22 s = year + "年" + month + "月" + data + "日 " + hour + ":" + minute + ":" + second; 23 } 24 25 return s; 26 } 27 else { 28 var dt = timeStamp.split(' '); 29 var s = dt; 30 if (dt.length > 1) { 31 var date = dt[0].split('/'); 32 var time = dt[1].split(':'); 33 var hour = '0' + time[0]; 34 hour = hour.substring(hour.length - 2); 35 if (type && type == 1) { 36 s = date[0] + "-" + date[1] + "-" + date[2] + " " + hour + ":" + time[1]; 37 } 38 else { 39 s = date[0] + "年" + date[1] + "月" + date[2] + "日 " + hour + ":" + time[1] + ":" + time[2]; 40 } 41 } 42 return s; 43 } 44 } 45 }