Reputation: 69
i want to parse a string into date having the below code, but output contains time also.
I don't want time in my output, I just want date.
public static void main(String args[]){
String givendate="2013-09-09";
Date date=(new SimpleDateFormat("yyyy-MM-dd").parse(givendate));
System.out.println(date);
}
Output of the program-: Mon Sep 09 00:00:00 IST 2013
Upvotes: 1
Views: 123
Reputation: 11443
Use Joda Time
DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yyyy");
DateTime dt = formatter.parseDateTime(string);
Upvotes: 0
Reputation: 11
The issue here is that when printing you are invoking the default format for printing the date object which includes time. Check out this link for the various formatting options
http://www.tutorialspoint.com/java/java_date_time.htm
Upvotes: 1
Reputation: 1489
Try using the same formatter when printing:
System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(date));
implicitely a Date
object contains time too.
Upvotes: 1