SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date = new Date();
String str = "2009-02-32";
try {
/*
* 指定日期/时间分析是否不严格
* 如果setLenient(false)设置为false,则表示要严格分析
* 例如在分析2009-02-32时就会报错
* 否则最后输出的数据为2009-03-04
*
*/
format.setLenient(false);
System.out.println(format.format(format.parse(str)));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SimpleDateFormat使用需要特别注意的地方
最新推荐文章于 2024-01-29 09:13:15 发布