I'd suggest looking at the SimpleDateFormat class - that can parse most formatted date strings into a Date object.
One thing I'd like to point out, though: there's no such thing as a "Date object in yy-MM-dd format". Date objects don't have a format. What you would want to do is convert the original string to a Date object, and then, when you need to display it somewhere, convert it back to a string in whatever format you want. You can do this with another SimpleDateFormat object matching the required output format.
sneha patil wrote:Thanks for reply...
when i parsed string,it giving parsing error....
can you give me example so that i can get better idea??
It's hard to guide you toward fixing your code if you don't show that code.
I will note, however, that if you currently have a String representing a date in one particular format, and you want to change it to a String representing a date in a different format, you will need two DateFormat objects.
As Matthew already said above, a Date object has no format. The toString() does some formatted output for you, but it will be always the same. If you want to have your Date as a String in certain format, you have to use a DateFormat again.
sneha patil wrote:..and i want this as a date object..
You already have it as a Date object. Your first line of code is this:
This means you've already got a Date object. As I said, this doesn't have any formatting. If you print it out it will use the toString() method, and that uses a default format. But the Date object itself has no format at all.
So you should just use this Date object until you need to print it out somewhere. At this point, you decide what format you want, and you use a SimpleDateFormat to convert it to a String using that format: