Resetting the time part of a timestamp in Java

后端 未结 10 1222
慢半拍i
慢半拍i 2020-12-04 23:56

In Java, given a timestamp, how to reset the time part alone to 00:00:00 so that the timestamp represents the midnight of that particular day ?

In T-SQL, this query

10条回答
  •  悲&欢浪女
    2020-12-05 00:27

    I prefer this solution:

    GregorianCalendar now = new GregorianCalendar();
    GregorianCalendar calendar = new GregorianCalendar(
                  now.get(GregorianCalendar.YEAR), now.get(GregorianCalendar.MONTH), 
                  now.get(GregorianCalendar.DAY_OF_MONTH));
    

提交回复
热议问题