|
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
public class DateFormatExample2 {
public static void main(String[] args) {
// Make a String that has a date in it, with MEDIUM date format
// and SHORT time format.
String dateString = xxxxxxxxxxx
" retrieve the datestring from the database for example - Nov 4, 2003 8:14 PM i.e the connection settings from the database and etc., Connection, Statement, ResultSet"
// Get the default MEDIUM/SHORT DateFormat
DateFormat format =
DateFormat.getDateTimeInstance(
DateFormat.MEDIUM, DateFormat.SHORT);
// Parse the date
try {
Date date = format.parse(dateString);
System.out.println("Original string: " + dateString);
System.out.println("Parsed date : " +
date.toString());
}
catch(ParseException pe) {
System.out.println("ERROR: could not parse date in string \"" +
dateString + "\"");
}
Ok this logic or the example program will help you
i hope you will get the results
Last edited by linuxswan : 07-19-2008 at 10:58 AM.
|