我想从Date
对象中删除时间。
DateFormat df;
String date;
df = new SimpleDateFormat("dd/MM/yyyy");
d = eventList.get(0).getStartDate(); // I'm getting the date using this method
date = df.format(d); // Converting date in "dd/MM/yyyy" format
但是当我转换这个日期(它是以String
格式表示的)时,它会附加时间。
我根本不想要时间。我想要的只是"21/03/2012"。
System.out.println(date)
是什么意思呢?它肯定已经是所需的格式了,对吧?否则你并没有发布完整的代码。例如,你可能会在稍后将其转换回Date
对象,这将获取默认时间。 - BalusCDate
呢?这有什么意义吗?Date
对象表示以毫秒为单位的时期时间戳,当然也包括时间。如果你的唯一目的是向人类展示它,只需按所需格式转换为String
,就像你已经做过的那样。你只需要在你要向人类展示它的那一刻进行转换。阅读javadoc:http://docs.oracle.com/javase/7/docs/api/java/util/Date.html(特别是`toString()`方法)。 - BalusC