如何在Java中将日期格式的字符串格式化为新的日期格式? [英] How can I format a String, which is a date, to a new date format in Java?
本文介绍了如何在Java中将日期格式的字符串格式化为新的日期格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我会直截了当,我的目标就是这样
I will get straight to the point, my goal it so change
2018-05-24
2018-05-24
进入
2018年5月24日。
May 24, 2018.
这是我当前的代码:
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);
但是运行该命令会产生:
But running that produces:
2018年1月24日。
January 24, 2018.
我不确定这是为什么告诉我1月。我知道我做错了,我已经在StackOverFlow中搜索了类似的问题,但是也许我做的不对。有建议吗?
I am not sure why this is telling me January. I know I have it wrong, I have searched StackOverFlow for similar questions, but maybe I am not doing something right. Any advice?
推荐答案
这是因为您一个月使用的是 mm
应该是 MM
:
It's because you're using mm
for month when it should be MM
:
SimpleDateFormat old = new SimpleDateFormat("yyyy-MM-dd");
此输出:
May 24, 2018.
这篇关于如何在Java中将日期格式的字符串格式化为新的日期格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文