将字符串转换为以下日期“ yyyy-mm-dd”格式
我正在尝试将字符串转换为date
,但是我无法获得我想要的格式。 我的代码是这样的:
String inputDate ="1948-06-29";
SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM-dd");
Date date = simpleDate.parse(inputDate);
System.out.println("Output : " + date); // Output: Tue Jun 29 00:00:00 CDT 1948
我希望日期打印出与这样的输入字符串相同的格式,例如“ 1948-06-29”,
请让我知道是否有任何解决方法。
I am trying to convert string to Date
, but I am not able to get the format that I want.
My code goes like this:
String inputDate ="1948-06-29";
SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM-dd");
Date date = simpleDate.parse(inputDate);
System.out.println("Output : " + date); // Output: Tue Jun 29 00:00:00 CDT 1948
I want the date to print out the same format as the input string like this "1948-06-29"
please let me know if there is any approach to solve this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 SimpleDateFormat#格式 :
Use
SimpleDateFormat#format
: