2013-08-30 28 views
1

我試圖替換一個字符:在生成的系統日期,所以我可以把它作爲一個標題。它給了我格式:「ago 29,2013 7:42:19 PM」,所以我需要改變「:」爲「」,用字符串替換。但我不知道該怎麼做。我很感激你的幫助。我的繼承人代碼:字符串替換android?

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

      } 
    } 
+0

看到這一點:http://stackoverflow.com/問題/ 5754363/Android的如何更換的部件 - 的 - 一個字符串按另一串 – Tobiel

回答

6

嘗試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.

2

難道你想要什麼:

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