Removing time from a Date object?

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

    java.util.Date represents a date/time down to milliseconds. You don't have an option but to include a time with it. You could try zeroing out the time, but then timezones and daylight savings will come into play--and that can screw things up down the line (e.g. 21/03/2012 0:00 GMT is 20/03/2012 PDT).

    What you might want is a java.sql.Date to represent only the date portion (though internally it still uses ms).

提交回复
热议问题