小编典典

如何将当前日期时间的格式设置为其他格式?

hibernate

我使用以下代码检索当前日期和时间,然后使用以下方法将其添加到表中。

 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

@Temporal(javax.persistence.TemporalType.TIMESTAMP)
    public Date getCurrentDateTime() {
        return date;
    }

阅读 455

收藏
2020-06-20

共1个答案

小编典典

要将日期更改为序号,您需要使用以下后缀。看看这个链接,以及

DD +     TH = DDTH  result >>>> 4TH

OR to spell the number add SP to the format

DD + SPTH = DDSPTH   result >>> FOURTH

还可以使用fmt库在jsp页面上设置日期格式

 <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

 <fmt:formatDate type="both" dateStyle="long" timeStyle="short" 
      value="${date}"/>
2020-06-20