Playing with conversion of dates
Frequently required script
Following code is used for the purpose of converting : Date Input in : String format into : java.sql.Date
private java.sql.Date stringToDate(String dateS) {
java.sql.Date sqlStartDate = null;
if (dateS != null && !"".equals(dateS)) {
String dateFormat = "yyyy-MM-dd";
SimpleDateFormat df = new SimpleDateFormat(dateFormat);
java.util.Date parsedDate1 = null;
{
try {
parsedDate1 = df.parse(dateS);
} catch (ParseException e) {
// TODO
}
sqlStartDate = new java.sql.Date(parsedDate1.getTime());
}
}
return sqlStartDate;
}
Following scrip tis used to convert String into oracle.jbo.domain.Date
private Date stringToDate(String dateS)
{
Date date=null;
if(dateS!=null && !"".equals(dateS) )
{
String dateFormat = "dd-MMM-yyyy";
SimpleDateFormat df = new SimpleDateFormat(dateFormat);
java.util.Date parsedDate1=null;
try
{
parsedDate1 = df.parse(dateS);
}
catch(ParseException e)
{
e.printStackTrace();
}
date = new Date(new Timestamp(parsedDate1.getTime()));
}
return date;
}
Frequently required script
Following code is used for the purpose of converting : Date Input in : String format into : java.sql.Date
private java.sql.Date stringToDate(String dateS) {
java.sql.Date sqlStartDate = null;
if (dateS != null && !"".equals(dateS)) {
String dateFormat = "yyyy-MM-dd";
SimpleDateFormat df = new SimpleDateFormat(dateFormat);
java.util.Date parsedDate1 = null;
{
try {
parsedDate1 = df.parse(dateS);
} catch (ParseException e) {
// TODO
}
sqlStartDate = new java.sql.Date(parsedDate1.getTime());
}
}
return sqlStartDate;
}
Following scrip tis used to convert String into oracle.jbo.domain.Date
private Date stringToDate(String dateS)
{
Date date=null;
if(dateS!=null && !"".equals(dateS) )
{
String dateFormat = "dd-MMM-yyyy";
SimpleDateFormat df = new SimpleDateFormat(dateFormat);
java.util.Date parsedDate1=null;
try
{
parsedDate1 = df.parse(dateS);
}
catch(ParseException e)
{
e.printStackTrace();
}
date = new Date(new Timestamp(parsedDate1.getTime()));
}
return date;
}
No comments:
Post a Comment