1

我试图替换一个字符:在生成的系统日期上,所以我可以把它作为标题。它给了我格式:“前 29, 2013 7:42:19 pm”,所以我需要用字符串替换来更改“”的“:”。但我不知道该怎么做。我很感激你的帮助。这是我的代码:

    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)
             {

             }
    }
4

2 回答 2

6

Try String.replace(old, new)

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

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

于 2013-08-30T00:57:51.050 回答
2

Is it what you want:

 String orig = "ago 29, 2013 7:42:19 p.m.";
String updated = orig.replace(":", " ");
System.out.println(updated);
于 2013-08-30T01:03:44.380 回答