如何从Date类型的变量中删除时间戳?

时间:2018-02-16 04:12:18

标签: java hibernate

我有一个Date类型的变量,其值从表单传递,但它将时间戳存储为00:00,如何删除该时间戳,或者如何设置正确的时间?

这是模型类:

     public class Offer {
     @Id
     @GeneratedValue(generator = "UUID")
     @GenericGenerator(
      name = "UUID",
       strategy = "org.hibernate.id.UUIDGenerator"
        )
     @Column(name = "offercode", updatable = false, nullable = false)

      private String offercode;

      @NotBlank
      private String offerName;

      private Date effectiveDate;
      }

JSP代码:

    <form action="http://localhost:8080/offer"  method="post">
    <tr><th>
    Offer Name<input type="text" name="offerName" placeholder="enter offer 
    name" required/><br></th></tr>
    <tr><th>
     Effective-Date<input type="text" name="effectiveDate" 
    placeholder="1/1/1990" required/><br></th></tr>
    <tr><th>
    Expiration Date<input type="text" name="expiryDate" 
     placeholder="1/1/1990" required/><br></th></tr>
    <tr><th>
     <input type="submit" value="CREATE"><br></th></tr>
    </form></table>
    </center>
   </body>

1 个答案:

答案 0 :(得分:0)

您可以使用SimpleDateFormat仅为dd / MM / YYYY格式化日期,也可以将@Temporal(TemporalType.Date)放在private Date effectiveDate