2008年4月23日 星期三

[Java] 取得現在的時間 (如:2008/04/24 11:38:23)

/**
* 事前準備:import java.util.Date; import java.text.SimpleDateFormat;
* 主要是要存入 datebase 欄位格式為datetime的欄位
*/
public String getDateTime(){
SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
Date date = new Date();
String strDate = sdFormat.format(date);
System.out.println(strDate);
return strDate;
}

沒有留言: