如何在Java中将String(日期)格式化为新的日期格式?

我会直截了当地说,我的目标就是如此改变

2018年5月24日

2018年5月24日。

这是我目前的代码:

String content = "2018-05-24"; SimpleDateFormat old = new SimpleDateFormat("yyyy-mm-dd"); Date oldDate = old.parse(content); SimpleDateFormat current = new SimpleDateFormat("MMMM dd, yyyy."); String newDate = current.format(oldDate); System.out.println(newDate); 

但运行产生:

2018年1月24日。

我不确定为什么这会告诉我一月。 我知道我错了,我已经在StackOverFlow中搜索了类似的问题,但也许我做的不对。 任何建议?

这是因为你应该使用mm作为MM

 SimpleDateFormat old = new SimpleDateFormat("yyyy-MM-dd"); 

这输出:

 May 24, 2018.