Skip to main content

Posts

Showing posts with the label format

unexpected output while converting a string to date in java

I have a string "12/9/2010 4:39:38 PM" which i have to convert to a date object. I am using the following code to do it: String str = "12/9/2010 4:39:38 PM"; DateFormat formatter ; Date date ; formatter = new SimpleDateFormat("M/dd/yyyy H:m:s a"); date =(Date)formatter.parse(str); System.out.println("date printed"+date); However, when im printing the output, i see Thu Dec 09 04:39:38 IST 2010 How do I get the date exactly the way I declared in the string i.e 12/9/2010 4:39:38 PM as output? Pls help