java中字符串轉換Date類型
阿新 • • 發佈:2018-06-18
time() sep timestamp sta epo clas end date類 posit
1 public static Date date(String date_str) { 2 try { 3 Calendar zcal = Calendar.getInstance();//日期類 4 Timestamp timestampnow = new Timestamp(zcal.getTimeInMillis());//轉換成正常的日期格式 5 SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");//改為需要的東西 6ParsePosition pos = new ParsePosition(0); 7 java.util.Date current = formatter.parse(date_str, pos); 8 timestampnow = new Timestamp(current.getTime()); 9 return timestampnow; 10 } 11 catch (NullPointerException e) { 12 returnnull; 13 } 14 }
java中字符串轉換Date類型