Removing time from a Date object?

前端 未结 19 1259
余生分开走
余生分开走 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:55

    Apache Commons DateUtils has a "truncate" method that I just used to do this and I think it will meet your needs. It's really easy to use:

    DateUtils.truncate(dateYouWantToTruncate, Calendar.DAY_OF_MONTH);
    

    DateUtils also has a host of other cool utilities like "isSameDay()" and the like. Check it out it! It might make things easier for you.

提交回复
热议问题