我遇到了jsp日期格式的问题,我希望复选框中的dd/mm/yyyy
而不是dd/mm/yyyy hh:mi:ss
,任何解决方案?
这是我的代码:
String sql1= "SELECT * from ajout_train";
PreparedStatement st1 = cnx.prepareStatement(sql1);
<tbody style="width: 105px">
<tr>
<td><label for="datedept">Départ le:</label></td>
<td> <select name="datedept" id="datedept"><%
if (st1.execute()) {
ResultSet rs1 = st1.getResultSet();
ResultSetMetaData rsmd = rs1.getMetaData();
while(rs1.next()) {
if (rs1.getObject(4) != null){
out.println("<option>"+rs1.getObject(4).toString()+"</option>");
}
}
}
%></select><%
%></td>
</tr>
答案 0 :(得分:0)
java中有内置类来格式化日期 使用此代码段。您可以参考此链接SimpleDateFormat了解详情
if (rs1.getObject(4) != null){
SimpleDateFormat inputdate = new SimpleDateFormat("dd/mm/yyyy hh:mm:ss");
SimpleDateFormat outputdate = new SimpleDateFormat("dd/mm/yyyy");
try {
String result = outputdate.format(inputdate.parse(rs1.getObject(4).toString()));
}
catch (Exception e) {
out.println(e);
}
out.println("<option>"+result+"</option>");
}
答案 1 :(得分:0)
用substring
解决了这个问题 enter code here
Départle:
&LT;%
if(st1.execute())
{
ResultSet rs1 = st1.getResultSet();
ResultSetMetaData rsmd = rs1.getMetaData();
while(rs1.next())
{
if (rs1.getObject(4) != null){
String result=(String)(rs1.getObject(4).toString());
result=result.substring(0,10);
out.println("<option>"+result+"</option>");
}
}
}
%></select><%
%></td>
</tr>