第一种方式:
<html>
<head><title>取得系统时间</title></head>
<body>
<%java.util.date date=new java.util.date();%>
现在是:<%=date%>
</body>
</html>
运行结果:
现在是:tue jul 31 10:32:52 cst 2001
第二种方式:
<%@ page import="java.util.*, java.text.*" %>
<html>
<head><title>显示当前时间</title></head>
<body>
当前时间:
<%
date now = new date();
out.println(dateformat.gettimeinstance().format(now));
%>
</body>
</html>
运行结果:
10:31:42 am
第三种方式:
<%
java.text.simpledateformat formatter = new java.text.simpledateformat("yyyy年mm月dd日");
java.util.date currenttime_1 = new java.util.date();
out.print(formatter.format(currenttime_1));
%>
运行结果:
2001年07月31日
第四种方式:
<%
java.text.simpledateformat formatter = new java.text.simpledateformat("yyyy/mm/dd hh/mm/ss");
java.util.date currenttime_1 = new java.util.date();
out.print(formatter.format(currenttime_1));
%>
运行结果:
2001/07/31 10/32/52
第三四两种方式其实是一样的他可以产生千变万化的格式。
闽公网安备 35060202000074号