Skip to content

Instantly share code, notes, and snippets.

@neilsonlima
Created January 24, 2020 15:11
Show Gist options
  • Save neilsonlima/de801fbedb01b5e534ad6484f287d98e to your computer and use it in GitHub Desktop.
Save neilsonlima/de801fbedb01b5e534ad6484f287d98e to your computer and use it in GitHub Desktop.
public class ExFormatationDate {
public static void main(String[] args) {
String dt1 = "20200124";
StringBuilder sb = new StringBuilder(dt1)
.insert(4,"-")
.insert(7,"-");
String output = sb.toString();
System.out.println(output);
String dt2 = "20200124";
String dataf = dt2.replaceAll("(\\d{4})(\\d{2})(\\d{2})", "$1-$2-$3");
System.out.println(dataf);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment