javascript格式化时间
示例:
function convertDate(time) { var oldDate = "/Date("+time+")/"; var realDate = new Date(parseInt(oldDate.replace("/Date(", "").replace(")/", ""), 10)); return getDateTime(realDate); } function getDateTime(date) { var year = date.getFullYear(); var month = date.getMonth() + 1; var day = date.getDate(); var hh = date.getHours(); var mm = date.getMinutes(); var ss = date.getSeconds(); return year + "-" + month + "-" + day + " " + hh + ":" + mm + ":" + ss; }
最终抽象:
/*javascript处理时间:格式化时间戳*/ function getDate(time) { /*通过时间戳实例化Date对象*/ var date = new Date(parseInt(time,10)); //使用Date对象获取年月日 var year = date.getFullYear(); var month = date.getMonth()+1; var day = date.getDate(); var value = year+"-"+month+"-"+day; // alert(value); return value; }

浙公网安备 33010602011771号