SimpleDateFormat 解析时忽略月份 [英] SimpleDateFormat ignoring month when parsing

查看:33
本文介绍了SimpleDateFormat 解析时忽略月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码为我提供了解析日期为Wed Jan 13 00:00:00 EST 2010"而不是Wed Jun 13 00:00:00 EST 2010".任何想法都非常感谢.

The following code is giving me the parsed date as "Wed Jan 13 00:00:00 EST 2010" instead of "Wed Jun 13 00:00:00 EST 2010". Any ideas much appreciated.

    SimpleDateFormat sf = new SimpleDateFormat("yyyy-mm-dd'T'HH:mm:ss");

    String str = "2010-06-13T00:00:00";

    Date date = sf.parse(str);

    System.out.println(" Date " + date.toString());

推荐答案

尝试:

"yyyy-MM-dd'T'HH:mm:ss"

MM 表示月份.mm 表示分钟.请参阅SimpleDateFormat<的文档/a> 有关支持的日期和时间模式的更多详细信息.

MM means month. mm means minutes. See the documentation for SimpleDateFormat for more details of the supported date and time patterns.

这篇关于SimpleDateFormat 解析时忽略月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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