使用下面代碼獲取當(dāng)前時(shí)間: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;
}
}創(chuàng)建了另一個(gè)類作為數(shù)據(jù)模型。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
}
}但是在分配當(dāng)期日期的時(shí)候報(bào)出錯(cuò)誤,不知道原因在那兒?請(qǐng)大俠幫忙。
java.sql.Timestamp拋出異常
慕桂英3389331
2019-03-13 18:15:15