public static Date strToDate(String strDate){ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); ParsePosition pos=new ParsePosition(0); Date strtodate=formatter.parse(strDate,pos); return strtodate; }
你的字串"2006-06-02-11.12.59.407756", 可以用 public static Date strToDate(String strDate){ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd-HH.mm.ss"); ParsePosition pos=new ParsePosition(0); Date strtodate=formatter.parse(strDate,pos); System.out.println("time="+strtodate); return strtodate; }
String timestr = "2006-06-02-11.12.59.407756"; java.sql.Date d = java.sql.Date.valueOf(timestr); String resultStr = (new SimpeDateFormatter("yyyy-MM-dd hh:MM:SS")).format(d); 试试看^_^
可以用下面function转换成yyyy-MM-dd hh:MM:SS的串 public String getDateLongString(Date currentTime) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateString=formatter.format(currentTime); return dateString; }
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ParsePosition pos=new ParsePosition(0);
Date strtodate=formatter.parse(strDate,pos);
return strtodate;
}
你的字串"2006-06-02-11.12.59.407756",
可以用
public static Date strToDate(String strDate){
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd-HH.mm.ss");
ParsePosition pos=new ParsePosition(0);
Date strtodate=formatter.parse(strDate,pos);
System.out.println("time="+strtodate);
return strtodate;
}
java.sql.Date d = java.sql.Date.valueOf(timestr);
String resultStr = (new SimpeDateFormatter("yyyy-MM-dd hh:MM:SS")).format(d);
试试看^_^
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString=formatter.format(currentTime);
return dateString;
}