1. 程式人生 > >獲取當前系統時間添加到對象中

獲取當前系統時間添加到對象中

pan format etc str val sta string orm notice

我數據庫中時間的類型是Timestamp

servlet中

Notice notice=new Notice();
notice.setTitle(title);
notice.setContext(context);
notice.setPublicer(name);
notice.setPublicerId(Integer.valueOf(id));

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//設置日期格式
String here=df.format(new Date());
Timestamp ts = Timestamp.valueOf(here);//類型轉換

notice.setWriteDate(ts);

獲取當前系統時間添加到對象中