我有个问题 String
转换为 Date
格式。请帮帮我。下面是我的代码:
String strDate = "23/05/2012"; // Here the format of date is MM/dd/yyyy
现在我想把上面的字符串转换成日期格式,比如“2012年5月23日”。
我正在使用下面的代码,但我得到的值为“wed may 23 00:00:00 bot 2012”
String string = "23/05/2012";
Date date = new SimpleDateFormat("MM/dd/yyyy", Locale.ENGLISH).parse(string);
System.out.println(date); // Wed May 23 00:00:00 BOT 2012
我怎样才能得到值为“2012年5月23日”。请帮助我的朋友。。。。
3条答案
按热度按时间t9eec4r01#
必须重新呈现日期。
你有了这个字符串,并将它正确地解析回
Date
对象。现在,你必须渲染它Date
以你想要的方式反对。你可以用
SimpleDateFormat
再次,改变模式。你的代码应该是apeeds0o2#
使用方法
format()
来自班级SimpleDateFormat
以正确的模式。使用简单:
zyfwsgd63#