利用JSP显示时间
JSP代码:
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" language="java" %>
<%@ page import="java.util.*"%>
<%@page import="java.text.SimpleDateFormat" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html: charset=UTF-8">
</head>
<body>
<%
response.addHeader("Refresh", "1");
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
out.println("当前的时间是:"+df.format(new Date()));
%><br/>
<a href="../index.jsp">返回首页</a><br/>
</body>
</html>
运行结果:
利用JS显示日期
JS代码:
<html>
<head>
<meta http-equiv="Content-Type" content=' text/html; charset=UTF-8'>
</head>
<body>
<script type="text/javascript">
var date=new Date();
document.write("当前时间是:"+date.toLocaleString()+"<br/>");
</script><br/>
<a href="../index.jsp">返回首页</a><br/>
</body>
</html>