引入JSLT标签:
<%@ taglib uri=
"http://java.sun.com/jsp/jstl/core"
prefix=
"c"
%>
<%@ taglib uri=
"http://java.sun.com/jsp/jstl/fmt"
prefix=
"fmt"
%>
字符串someDate:
<c:set var=
"someDateStr"
value=
"2014-05-08 18:02:01"
/>
转换Date对象:
<fmt:parseDate var=
"someDate"
value=
"${someDateStr}"
pattern=
"yyyy-MM-dd HH:mm:ss"
/>
parseDate:${someDateStr} >> ${someDate}
页面输出:
parseDate:2014-05-08 18:02:01 >> Thu May 08 18:02:01 CST 2014
当前时间对象:
<jsp:useBean id=
"nowDate"
class
=
"java.util.Date"
/>
格式化为字符串:
<fmt:formatDate var=
"nowStr"
value=
"${nowDate}"
pattern=
"yyyy/MM/dd HH:mm:ss"
/>
formatDate:${nowDate} >> ${nowStr}
页面输出:
formatDate:Thu May 08 18:49:57 CST 2014 >> 2014/05/08 18:49:57
计算时间差:
<c:set var=
"interval"
value=
"${nowDate.time - someDate.time}"
/>
时间间隔(毫秒):${interval}
页面输出:
时间间隔(毫秒):2876802
转换为分钟:
<fmt:formatNumber value=
"${interval/1000/60}"
pattern=
"#0.0"
/>
页面输出: 47.9