********************DateConvert.java******************************
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class DateConvert
{
public DateConvert() throws ParseException
{
String dateString = "2011/10/23";
//set the format,in which you are going to represent date
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
//parse it and get it in util date format
java.util.Date utilDate = dateFormat.parse(dateString);
//converting Util Date into sql Date
java.sql.Date sqlDate= new java.sql.Date(utilDate.getTime());
System.out.println("Util Date Format: " + utilDate);
System.out.println("Sql Date Format: " + sqlDate);
}
public static void main(String[] argv)throws Exception
{
new DateConvert();
}
}
*******************************Prog-Ends**********************************
Note:- make sure to keep MM in uppercase
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class DateConvert
{
public DateConvert() throws ParseException
{
String dateString = "2011/10/23";
//set the format,in which you are going to represent date
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
//parse it and get it in util date format
java.util.Date utilDate = dateFormat.parse(dateString);
//converting Util Date into sql Date
java.sql.Date sqlDate= new java.sql.Date(utilDate.getTime());
System.out.println("Util Date Format: " + utilDate);
System.out.println("Sql Date Format: " + sqlDate);
}
public static void main(String[] argv)throws Exception
{
new DateConvert();
}
}
*******************************Prog-Ends**********************************
Note:- make sure to keep MM in uppercase
No comments:
Post a Comment