This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
First of all, there is an error in line 7 of your code:
This should have been:
Note that you must use "MM" for the month, not "mm", because "mm" means minutes.
Krish Khan wrote:i am getting date as Jan 22 10:32:00 SGT 2010
Note that a Date object does not know anything about formatting by itself. If you print a Date object like you are doing in line 9 of your code, then a default format will be used to convert the Date to a String for display. If you want the date to be printed in a specific format, you must use the SimpleDateFormat object again to convert it to a string in the desired format: