Converting String to Date object
Below is the code for converting String of specified format into Date object. This code uses SimpleDateFormat class for converting String to Date.
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateUtils {
public static void main(String[] args) {
DateFormat dateFormat = new SimpleDateFormat("yyyy-dd-mm");
String strNow = "2008-11-03";
// Convert given String to date object
try {
Date todayDate = dateFormat.parse(strNow);
System.out.println(todayDate);
} catch (ParseException e) {
e.printStackTrace();
}
}
}
August 17, 2008 | Filed Under Java
Related Post
Comments
Leave a Reply