往数据库中添加日期格式为年月日,如(20101208),jsp页面中怎么写。

<input type="hidden" name="date" value=""/>我想得到当前时间。
2025-05-09 15:29:41
推荐回答(3个)
回答1:

<%@page import ="java.util.*,java.text.*"%>

<%
SimpleDateFormat template= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String now= template.format(new java.util.Date());
%>


//时间格式是随便你调的 如果你只要20101208
<%
SimpleDateFormat template= new SimpleDateFormat("yyyyMMdd HH:mm:ss");
String today = template.format(new java.util.Date()).substring(0,8);
%>

回答2:

页面可以这么写
后台处理时可以转换成java.Sql.Date类型存到数据库中 。
在页面上直接用 new Date()就行了,可以尝试一下。

回答3:

<%@page
import
="java.util.*,java.text.*"%>
<%
SimpleDateFormat
template=
new
SimpleDateFormat("yyyy-MM-dd
HH:mm:ss");
String
now=
template.format(new
java.util.Date());
%>
type="hidden"
name="date"
value="<%=now%>"/>
//时间格式是随便你调的
如果你只要20101208
<%
SimpleDateFormat
template=
new
SimpleDateFormat("yyyyMMdd
HH:mm:ss");
String
today
=
template.format(new
java.util.Date()).substring(0,8);
%>
type="hidden"
name="date"
value="<%=today
%>"/>