java SimpleDateFormat模式与参数不同 [英] java SimpleDateFormat pattern different with argument

查看:80
本文介绍了java SimpleDateFormat模式与参数不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SimpleDateFormat模式为 yyyyMM,而arg为yyyy-MM,但没有例外,也没有错误的结果。为什么? thx ~~

SimpleDateFormat pattern is "yyyyMM", and the arg is yyyy-MM, but there are no exception and a wrong result. why? thx~~

SimpleDateFormat format = new SimpleDateFormat("yyyyMM");
System.out.println(format.format(format.parse("2011-07")));

结果为201105

推荐答案

使用 setLenient(false);

请参见 setLenient()文档

这篇关于java SimpleDateFormat模式与参数不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆