如何将当前日期时间的格式设置为不同的格式? [英] How to set format of current date time to different format?
本文介绍了如何将当前日期时间的格式设置为不同的格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用以下代码检索当前日期和时间,然后使用以下方法将其添加到表中。
I use the following code to retrieve the current date and time, then add it to table using following method.
Change 2013-07-29 23:20:34.0 to 29th July 2013, 11:20 PM
日期时间
public Date getCurrentDateTime() {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
System.out.println("current:" + dateFormat.format(date));
return date;
}
Hibernate
Hibernate
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
public Date getCurrentDateTime() {
return date;
}
推荐答案
To change the day to ordinal number you need to use the following suffix. have a look at this link as well
DD + TH = DDTH result >>>> 4TH
OR to spell the number add SP to the format
DD + SPTH = DDSPTH result >>> FOURTH
另请使用fmt库格式化jsp页面上的日期
Also use the fmt library to format the date on jsp pages
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<fmt:formatDate type="both" dateStyle="long" timeStyle="short"
value="${date}"/>
这篇关于如何将当前日期时间的格式设置为不同的格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文