2018-05-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);
但运行产生:
January 24, 2018.
我不知道为什么这会告诉我一月.我知道我错了,我已经在StackOverFlow中搜索了类似的问题,但也许我做的不对.有什么建议?
解决方法:
这是因为你应该使用mm作为MM:
SimpleDateFormat old = new SimpleDateFormat("yyyy-MM-dd");
这输出:
May 24, 2018.
标签:java,date,simpledateformat
来源: https://codeday.me/bug/20190930/1834309.html