I am taking the current time using following method:
import java.sql.Timestamp;
public class TimeFormat
{
public static Timestamp getCurrentDateAndTime()
{
String strFormat = new String("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat formatter = new SimpleDateFormat(strFormat);
java.util.Date theDate = new java.util.Date();
theDate = (java.util.Date) formatter.parse(formatter.format(theDate));
Timestamp rtnTS = new Timestamp(theDate.getTime());
return rtnTS;
}
}
Now created another class as a data model:
public class InvoiceObject extends java.lang.Object implements Serializable
{
public Integer mId;
public Timestamp mTimeIssued;
public InvoiceObject()
{
this.mId = new Long("0");
Timestamp tempTime = TimeFormat.getCurrentDateAndTime(); //successful
this.mTimeIssued = tempTime; //here throwing error
}
}
Can't understand why it's throwing error during assign the current date
java.sql.Timestampwhen your data clearly isn't a full timestamp, anyway? If you've only got data to the level ofjava.util.Date, why not stick with that?)getCurrentDateAndTime()didn't ask you to either throw or catch a certainParseException.