【JSP EL】EL表达式获取当前时间(三种方式)

第一种方式:

//先在代码段定义
<% long date = new Date().getTime(); request.setAttribute("date", date); %>
//然后EL表达式引用
${date}

或者
 
//同样道理 这里得到时间                           
<% Date nowDate = new Date(); request.setAttribute("nowDate", nowDate); %>

${nowDate}

第二种:

在JSP页首引用:

<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

在使用的地方:

<jsp:useBean id="now" class="java.util.Date" scope="page"/>
<fmt:formatDate value="${now}" pattern="yyyy年MM月dd日" />

第三种:

页面:

<div>
   <span id="sysTime"></span>
</div>

js代码:

$(document).ready(function () {
        <!--年月日-->
        var dateTime = new Date();
        var year = dateTime.getFullYear();
        var month = (dateTime.getMonth() + 1).toString();
        var day = dateTime.getDate();
        if (month.length == 1) {
            month = "0" + month;
        }
        if (day < 10) {
            day = "0" + day;
        }
        var font = document.getElementById("sysTime");
        var stringTime = year + "<@spring.message "head.year"/>" + month + "<@spring.message "head.month"/>" + day + "<@spring.message "head.day"/>";
        font.innerHTML = stringTime;
    });

猜你喜欢

转载自blog.csdn.net/supershuyun/article/details/87685383