public Date parse(String text, ParsePosition pos)解析字符串的文本,生成 Date。 此方法试图解析从 pos 给定的索引处开始的文本。如果解析成功,则将 pos 的索引更新为所用最后一个
字符后面的索引(不必对直到字符串结尾的所有字符进行解析),并返回解析得到的日期。更新后的
pos 可以用来指示下次调用此方法的起始点。如果发生错误,则不更改 pos 的索引,并将 pos 的
错误索引设置为发生错误处的字符索引,并且返回 null。 指定者: 类 DateFormat 中的 parse 参数: text - 应该解析其中一部分的 String。 pos - 具有以上所述的索引和错误索引信息的 ParsePosition 对象。 返回: 从字符串进行解析的 Date。如果发生错误,则返回 null。 抛出: NullPointerException - 如果 text 或 pos 为 null。 用这个方法 public static Date StringToDate(String dateStr,String formatStr){ DateFormat dd=new SimpleDateFormat(formatStr); Date date=null; try { date = dd.parse(dateStr); } catch (ParseException e) { e.printStackTrace(); } return date; }