Hello World,
I have date in String "mm/dd/yy" format I want to conver it into String format "yyyy-mm-dd".
I am doing this like
String MY_DATE_FORMAT = "yyyy-MM-dd";
Date d = new Date("05/18/05");
String expDate = new SimpleDateFormat(MY_DATE_FORMAT).format(d);
System.out.println(expDate);
Is there other good way to do this. Because the constructor of Date is depricated now.
I have tried parse() method of DateFormat but it is giving me exception.
I have tried something like this
try {
DateFormat df = new SimpleDateFormat();
Date d = df.parse("05/18/05");
String MY_DATE_FORMAT = "yyyy-MM-dd";
String expDate = new SimpleDateFormat(MY_DATE_FORMAT).format(d);
System.out.println(expDate);
} catch(Exception e) {
e.printStackTrace();
}
This code gives me exception :
java.text.ParseException: Unparseable date: "05/18/05"
at java.text.DateFormat.parse(DateFormat.java:345)
at StringTest.main(StringTest.java:19)
Experts, please help me in this as early as possible.
Hello World,
I have date in String "mm/dd/yy" format I want to
conver it into String format "yyyy-mm-dd".
if this is the input :- MM/dd/yy
and this is the desired output :- yyyy-MM-dd
String strTmp = "09/21/04";
Date dtTmp = new SimpleDateFormat("MM/dd/yy").parse(strTmp);
String strOutDt = new SimpleDateFormat("yyyy-MM-dd").format(dtTmp);
ParsePosition pos = new ParsePosition(0);
Date dtTmp = new SimpleDateFormat("MM/dd/yy").parse(strTmp, pos);
String strOutDt = new SimpleDateFormat("mm/dd/yyyy").format(dtTmp);