日期:2014-05-20 浏览次数:20854 次
import java.sql.Timestamp; import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.Date; public class Test { public static void main(String[] args) { System.out.println(fmtStr2Date("2012-06-21 10:00:0000","yyyyMMddHHmmss").toString()); } public static Date fmtStr2Date(String strDate, String fmt){ Timestamp dt = null; if (strDate != null && strDate.equals("") == false) { try { SimpleDateFormat formatter = new SimpleDateFormat(fmt); ParsePosition pos = new ParsePosition(0); java.util.Date cDate = formatter.parse(strDate, pos); dt = new Timestamp(cDate.getTime()); } catch (Exception e) { //logger.error("\nstrDate="+strDate + " fmt="+fmt,e); } } return dt; } }
import java.sql.Timestamp; import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.Date; public class Test11 { public static void main(String[] args) { System.out.println(fmtStr2Date("2012-06-21 10:00:0000","yyyy-MM-dd HH:mm:ss").toString()); } public static Date fmtStr2Date(String strDate, String fmt){ Timestamp dt = null; if (strDate != null && strDate.equals("") == false) { try { SimpleDateFormat formatter = new SimpleDateFormat(fmt); ParsePosition pos = new ParsePosition(0); java.util.Date cDate = formatter.parse(strDate, pos); dt = new Timestamp(cDate.getTime()); } catch (Exception e) { //logger.error("\nstrDate="+strDate + " fmt="+fmt,e); } } return dt; } }
------解决方案--------------------
懂了就好,那种满足感,大家都明白。
------解决方案--------------------
接分 既然楼主懂了 那就均分吧 哈哈~~
------解决方案--------------------