Java Program to format date time with Join

Java 8Object Oriented ProgrammingProgramming

To format date time with Join, set the date as a string and do not forget to add the delimeter.

For delimeter “/” in the date

String.join("/","11","11","2018");

For delimeter “:” in the date.

String.join(":", "10","20","20");

The following is an example.

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      String d = String.join("/","11","11","2018");
      System.out.print("Date: "+d);
      String t = String.join(":", "10","20","20");
      System.out.println("\nTime: "+t);
   }
}

Output

Date: 11/11/2018
Time: 10:20:20
raja
Published on 17-Dec-2018 06:33:49
Advertisements