How can i get a date instance without a time stamp in java? Ex: 2013-05-23( date instance)
Asked
Active
Viewed 112 times
-2
-
1format your date with `yyyy-MM-dd` format – Subhrajyoti Majumder Mar 05 '13 at 18:01
-
http://stackoverflow.com/questions/999172/how-to-parse-date-in-java – Karl-Bjørnar Øie Mar 05 '13 at 18:02
2 Answers
2
Create a Calendar object to store the date, clear out the time fields, and then get the resulting date:
Calendar cal = Calendar.getInstance();
cal.setTime(dateYouWantToTruncate);
cal.clear(Calendar.HOUR);
cal.clear(Calendar.MINUTE);
cal.clear(Calendar.SECOND);
cal.clear(Calendar.MILLISECOND);
Date dateOnly = cal.getTime();

jalynn2
- 6,397
- 2
- 16
- 15
2
If you just want to print out the date use this:
DateFormat.getDateInstance().format(new Date());
or
DateFormat.getDateInstance(DateFormat.SHORT).format(new Date());

Marcin
- 2,399
- 3
- 17
- 15