I have the following date:
formattedStr = "4-3-2011 23:11:0";
I want it in the format MM-DD-YYYY HH:MM:SS
I tried using formatter but it didn't help:
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date sampleDate = formatter.parse(formattedStr);
Does anyone know how to do this?
There should be %T tags which print a certain number of characters, eg 04 for April rather than 4. Pass the Date object as an argument to the format String. Details in the documentation for java.util.Formatter.
To turn a String representing a date into another String representing the same date but in a different format, you must first use one DateFormat to parse the String into a Date, then use another DateFormat to format that Date back into a String.