1. 程式人生 > >前臺將sql.Timestamp的日期型別轉為String

前臺將sql.Timestamp的日期型別轉為String

function time(timestamp) {
        var time = new Date(timestamp);
        var y = time.getFullYear();
        var m = (time.getMonth() + 1) < 10 ? "0" + (time.getMonth() + 1) : (time.getMonth() + 1);//獲取當前月份的日期,不足10補0
        var d = time.getDate() < 10 ? "0" + time.getDate() : time.getDate();//獲取當前幾號,不足10補0s
        return y + "/" + m + "/" + d + " " + time.toTimeString().substr(0, 5);
    }

或者在前臺匯入<%@ taglib prefix=“fmt” uri=“http://java.sun.com/jsp/jstl/fmt” %>後

<fmt:formatDate value="${timestamp}" pattern="yyyy/MM/dd HH:mm"/></p>