Removing time from a Date object?

前端 未结 19 1293
余生分开走
余生分开走 2020-12-15 02:26

I want to remove time from Date object.

DateFormat df;
String date;
df = new SimpleDateFormat(\"dd/MM/yyyy\");
d = eventList.get(0).getStartDate         


        
19条回答
  •  无人及你
    2020-12-15 02:51

    In addtition to what @jseals has already said. I think the org.apache.commons.lang.time.DateUtils class is probably what you should be looking at.

    It's method : truncate(Date date,int field) worked very well for me.

    JavaDocs : https://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/time/DateUtils.html#truncate(java.util.Date, int)

    Since you needed to truncate all the time fields you can use :

    DateUtils.truncate(new Date(),Calendar.DAY_OF_MONTH)
    

提交回复
热议问题