(1)默认录入日期为当天
首先注意,在jsp页面中要写java代码的话需要用<%%>。
<!-- 使用 SimpleDateFormat这个要引入下面的包-->
<%@page import="java.text.SimpleDateFormat" %>
<!-- 当前登记日期日期 -->
<%SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String value = format.format(new Date());
%>
上面的代码是在jsp页面中写的,
<tr>
<td align="right">
<label class="Validform_label">
登记日期:
</label>
</td>
<td class="value" colspan="3">
<span class="Validform_checktip">*</span>
<input id="inputDate" name="inputDate" type="text" datatype="*" style="width: 150px" class="Wdate" onClick="WdatePicker()" value="<%=value%>">
<label class="Validform_label" style="display: none;">登记日期</label>
</td>
</tr>
上述代码中, value="<%=value%>"得到了当前日期的值。
下面是java的一个测试:
import java.text.SimpleDateFormat;
import java.util.Date;
public class Test
{
public static void main(String[] args)
{
//利用构造函数设置格式化模板,yyyy年MM月dd日 HH时mm分ss秒
SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
Date date = new Date();
//执行格式化功能
System.out.println(formatter.format(date));
//设置格式化模板
formatter.applyPattern("yyyy-MM-dd");
System.out.println(formatter.format(date));
}
}
结果是:
2018年05月09日 16时06分36秒
2018-05-09
(2)下面是在一个日期控件上获得一个当前的时间并且可以编辑。
<tr>
<td align="right">
<label class="Validform_label">
生产日期:
</label>
</td>
<td class="value">
<!-- 因为在Controller中已经获得到了当前日期:ttppSample = new TtppSampleEntity();
ttppSample.setProductionDate(DateUtils.getDate("yyyy-MM-dd"));
所以,在这里可以直接记性引用,-->
<input id="productionDate" name="productionDate" type="text" style="width: 150px" datatype="*"
class="Wdate" onClick="WdatePicker()" value="${ttppSamplePage.productionDate}">
<span class="Validform_checktip">*</span>
<label class="Validform_label" style="display: none;">生产日期</label>
</td>
</tr>