1.對字符串的時間格式 yyyy-MM-dd HH:mm:ss 相關操做java
public static void main(String[] args) throws ParseException { String time = "2015-10-08 17:56:59"; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); java.util.Date date_util = sdf.parse(time); //轉換爲util.date java.sql.Date date_sql = new java.sql.Date(date_util.getTime()+(long)(0.5*60*60*1000));//轉換爲sql.date System.out.println(date_util); System.out.println(date_sql); String date = sdf.format(date_sql); System.out.println(date); date = sdf.format(date_util); System.out.println(date); }