Java Program to format date time with 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("
Time: "+t);    } }

Output

Date: 11/11/2018
Time: 10:20:20

Updated on: 27-Jun-2020

235 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements