0

I'm using the LocalDateTime.now() method to get the current time and date for the filenames for file reports, and colons are not allowed in filename.

How can I replace every colon (":") with a period (".") in the String so it's acceptable to set as a filename?

Chromatica
  • 123
  • 7

3 Answers3

6

use format() method

How to parse/format dates with LocalDateTime? (Java 8)

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH.mm");
String formattedDateTime = dateTime.format(formatter); // "2015-07-07 12.30"

http://ideone.com/bQGPE3

Community
  • 1
  • 1
Kalpesh Soni
  • 6,879
  • 2
  • 56
  • 59
1

Take a look at string replace.

Gerard Abello
  • 658
  • 3
  • 7
0

String.replace will solve this for you.

String date = "01:02:1990";
System.out.println(date); //01:02:1990
String amendedDate = date.replace(":", ".");
System.out.println(amendedDate); //01.02.1990