gpt4 book ai didi

java - 转换日期: d-M-yyyy to dd-MM-yyyy

转载 作者:行者123 更新时间:2023-12-02 00:32:10 29 4
gpt4 key购买 nike

Possible Duplicate:
Conversion of Date

我从对话框中获取的日期为:5-1-2012 - 作为字符串。

我需要将其转换为 05-01-2012,字符串。最简单的方法是什么?

最佳答案

你的意思是?

String date = "5-1-2012";
if (date.charAt(1) == '-') date = "0" + date;
if (date.charAt(4) == '-') date = date.substring(0,3) + "0" + date.substring(3);
// date is 05-01-2012

关于java - 转换日期: d-M-yyyy to dd-MM-yyyy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8743306/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com