将字符串转换为以下日期“ yyyy-mm-dd”格式

发布于 2025-02-09 00:57:07 字数 417 浏览 0 评论 0原文

我正在尝试将字符串转换为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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

递刀给你 2025-02-16 00:57:07

使用 SimpleDateFormat#格式

System.out.println("Output : " + simpleDate.format(date));

Use SimpleDateFormat#format:

System.out.println("Output : " + simpleDate.format(date));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文