使用SimpleDateFormat获取月份名称错误 [英] getting month name wrong with SimpleDateFormat

查看:60
本文介绍了使用SimpleDateFormat获取月份名称错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这小段代码有疑问

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

String str = "2010-03-13 01:01:22";

Date date = sf.parse(str);

SimpleDateFormat f = new SimpleDateFormat("d MMM yyyy hh:mm aaa");

System.out.println(" Date " + f.format(date));   

输出:

 Date 13 Jan 2010 01:01 AM

代码似乎很好,但是我仍然弄错了月份名称.请帮忙 !!谢谢.

The code seems to be fine but still I am getting month name wrong. Please help !! Thanks.

推荐答案

您在模式中使用的是分钟而不是月份.应该是:

You are using minute instead of month in your pattern. It should be:

yyyy-MM-dd HH:mm:ss

这篇关于使用SimpleDateFormat获取月份名称错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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