Format Date and Time in Java using Join



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
Updated on: 2020-06-27T06:31:35+05:30

312 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements