Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Hi all,
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Test1 {
public static void main(String[] args) {
SimpleDateFormat formatter;
String output;
formatter = new SimpleDateFormat("MM/dd/yyyy");
Date d = null;
try {
d = formatter.parse("12/20/08");//user entry date
} catch (ParseException e) {
e.printStackTrace();
}
output = formatter.format(d.getTime());
System.out.println(output);
}
}The above code formats date string to the given format.
If user gives "12/20/2008" it prints 12/20/2008
If user gives "12/20/08" it prints 12/20/0008 but i need 12/20/2008 (year should be current year(2008) not 0008). How can I achieve this?
Thanks.
-arun