使用下面代码获取当前时间: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;
}
}创建了另一个类作为数据模型。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
}
}但是在分配当期日期的时候报出错误,不知道原因在那儿?请大侠帮忙。
添加回答
举报
0/150
提交
取消