jsp时间格式化

来源:互联网 发布:mac book怎么样 编辑:程序博客网 时间:2024/06/05 07:46
第一步:先导入jstl
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

第二步:在需要修改时间格式的地方
如:
<fmt:formatDate value="${i.createDate }" pattern="yyyy-MM-dd HH:mm:ss"/>

pattern属性里面可以修改自己想要的时间格式。

这样就可以在JSP以自己想要的形式显示。

---------------------------------------------

SimpleDateFormat类  --- 时间、字符串的相互转换

SimpleDateFormat myFmt=new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
SimpleDateFormat myFmt1=new SimpleDateFormat("yy/MM/dd HH:mm"); 
SimpleDateFormat myFmt2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//等价于now.toLocaleString()
SimpleDateFormat myFmt3=new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒 E ");
SimpleDateFormat myFmt4=new SimpleDateFormat(
"一年中的第 D 天 一年中第w个星期 一月中第W个星期 在一天中k时 z时区");
Date now=new Date();
System.out.println(myFmt.format(now));
System.out.println(myFmt1.format(now));
System.out.println(myFmt2.format(now));
System.out.println(myFmt3.format(now));
System.out.println(myFmt4.format(now));
System.out.println(now.toGMTString());
System.out.println(now.toLocaleString());
System.out.println(now.toString());
原创粉丝点击