This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
1. You enclose the date string in double quotes. Otherwise, it won't compile.
2. Take out the colon between the date and time. Otherwise, it won't parse.
3. Use doj.getDay() not doj.getday(). Again, it won't compile otherwise.
That returns 6, which means that the date is on a Saturday.
Also that's a deprecated call. The new Java specs say to use a Calendar rather than calling the functions on Date directly. I believe those methods have been deprecated for nearly 10 years already.
Joined: Jan 08, 2010
thanks for your reply.
I have tried to use like bleow using Calendar.
It didn't work correctly.
I want the whatever the input string to be parsed(ie :2010-01-16 12:50:05)
ItDoesntWorkIsUseless. What do you expect, and what do you get? You do know that the calendar months start at 0, not 1? So if mm is 0 then that means January. You should compare the return value against Calendar.JANUARY, Calendar.FEBRUARY, ..., Calendar.DECEMBER. The day of week is likewise just a number from Calendar.SUNDAY to Calendar.SATURDAY, inclusive.
To get a month starting at 1 just do a little calculation: