gpt4 book ai didi

java - 字符串替换android?

转载 作者:行者123 更新时间:2023-11-29 10:15:44 25 4
gpt4 key购买 nike

我正在尝试替换一个字符:在生成的系统日期上,以便我可以将其作为标题。它给了我格式:“ago 29, 2013 7:42:19 p.m.”,因此我需要将“:”更改为“”,并用字符串替换。但我不知道该怎么做。非常感谢您的帮助。这是我的代码:

    public void createPDF()
{
Document doc = new Document();


try {
Date date = new Date();
String dateTime = DateFormat.getDateTimeInstance().format(date);
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdCard.getAbsolutePath() + "/Bitacora");
dir.mkdirs();
File file = new File(dir, "Bitácora "+idetotrocliente.getText().toString()+", "+dateTime+etsitio.getText().toString()+".pdf");
FileOutputStream fOut = new FileOutputStream(file);
}
catch(Exception)
{

}
}

最佳答案

尝试 String.replace(old, new)

String dateTime = "ago 29, 2013 7:42:19 p.m.";
dateTime = dateTime.replace(":", " ");
System.out.println("dateTime : "+dateTime);

输出:dateTime:ago 29, 2013 7 42 19 p.m.

关于java - 字符串替换android?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18523262/

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