I am new to Java and was trying to convert a String
date to a certain java.util.Date
format. The un-parsed
String date is in yyyy-MM-dd HH:mm:ss
pattern and I want to change it todd-MM-yyyy
, for that I wrote some first implementation as follows below:
import java.text.SimpleDateFormat;
public class testDate {
public void parseDate() {
try {
String testDate = "2015-06-19 00:00:00.000000";
SimpleDateFormat format1 = new SimpleDateFormat("dd-MM-yyyy");
java.util.Date parsedDate = format1.parse(testDate);
System.err.println(parsedDate);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
testDate td = new testDate();
td.parseDate();
}
}
The output Tue Dec 05 00:00:00 IST 24
is unexpected for me as a novice :).
So, I would request to suggest or point out where am I going wrong. Thanks
N.B:- There is a similar post (Convert java.util.Date to String) but it talks about parsing one Date
format to another, but not String
to a different Date
Format