OpenCms时间类型字段内容格式化并输出
转载请表明出处:http://javajiao.iteye.com/admin/blogs/256507
自己定义的内容类型的资源文件,如果其中包含的时间类型,显示的时候着实麻烦。
默认在OpenCms系统中,时间存储的类型是long型的,你如果想显示必须要格式化一下。
搜罗了一下转化的方法,列举在下面:
Method 1.
<cms:contentload collector="singleFile" param="%(opencms.uri)" editable="true" > <cms:contentaccess var="content" /> ... ... <p><fmt:formatDate value="${cms:convertDate(content.value['PublishDate'])}" type="date" dataStyle="LONG" /></P> ... ...</cms:contentload>Method 2.
<cms:contentload collector="singleFile" param="%(opencms.uri)" editable="true"><c:set var="temp_Date"><cms:contentshow element="PublishDate" /></c:set> <% long longDate = Long.valueOf(pageContext.getAttribute("temp_Date").toString()).longValue(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); String publishDate = sdf.format(new Date(longDate)); out.print(publishDate); %></cms:contentload>PS:在使用的时候一定义注意将相关的taglib包引入。
如果是用程序就好办了,直接可以读取对应资源文件里面的资源,然后再将其格式化输出。 1 楼 sdcyst 2009-02-20 时间格式有多少种呢? 2 楼 javajiao 2009-02-24 这个就是java的那个类包 有很多种 你可以自己查查api.