各位大侠们好,我是一名刚学习java不久的菜鸟,我在jsp界面里写了显示系统时间的语句,运行后发现
显示的时间与系统的时间不符,小弟在这里有情各位大侠帮忙解释一下
代码如下:
<%@ page language="java" import="java.util.*,java.text.SimpleDateFormat" pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.SIMPLIFIED_CHINESE).format(Calendar.getInstance().getTime())%>
</body>
</html>
显示的时间与系统的时间不符,小弟在这里有情各位大侠帮忙解释一下
代码如下:
<%@ page language="java" import="java.util.*,java.text.SimpleDateFormat" pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.SIMPLIFIED_CHINESE).format(Calendar.getInstance().getTime())%>
</body>
</html>
Date d = new Date();
System.out.println(c.getTime().toLocaleString());
<div id="datad"></div>
</body> js:
function DateDemo(){
var d, s = "Today's date is: "; // 声明变量。
d = new Date(); // 创建 Date 对象。
s += d.getYear()+ "-"; // 获取年份。
s += (d.getMonth() + 1) + "-"; // 获取月份。
s += d.getDate(); // 获取日。
var c = ":";
s += d.getHours() + c;
s += d.getMinutes() + c;
s += d.getSeconds() + c;
s += d.getMilliseconds();
document.getElementById("datad").innerText =s
}