/** * 字符串转日期格式 * */ public static Date date(String date_str) { try { Calendar zcal = Calendar.getInstance(); Timestamp timestampnow = new Timestamp(zcal.getTimeInMillis()); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); ParsePosition pos = new ParsePosition(0); java.util.Date current = formatter.parse(date_str, pos); timestampnow = new Timestamp(current.getTime()); return timestampnow; } catch (NullPointerException e) { return null; } }
本文详细介绍了如何使用Java将字符串转换为日期格式,通过实例演示了利用SimpleDateFormat和Timestamp实现日期解析的过程,包括异常处理。

被折叠的 条评论
为什么被折叠?



