1

Im trying to replace a character : on a system date generated so I can put it as a title. It gives me the format: "ago 29, 2013 7:42:19 p.m.", so I need to change the ":" for " ", with an string replace. But I dont know how to do it. Ill appreciate your help. Heres my code:

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

             }
    }
Sanket Shah
  • 4,352
  • 3
  • 21
  • 41
Miguel
  • 115
  • 2
  • 3
  • 14
  • see this: http://stackoverflow.com/questions/5754363/android-how-to-replace-part-of-a-string-by-another-string – Tobiel Aug 30 '13 at 00:59

2 Answers2

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.

newuser
  • 8,338
  • 2
  • 25
  • 33
2

Is it what you want:

 String orig = "ago 29, 2013 7:42:19 p.m.";
String updated = orig.replace(":", " ");
System.out.println(updated);
Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136