Java Data Type How to - Add colon to 24 hour time








Question

We would like to know how to add colon to 24 hour time.

Answer

import java.text.SimpleDateFormat;
import java.util.Date;
//from   w  w w.  j av a2  s.  c o  m
public class Main {
  public static void main(String[] args) {
    Date d = new Date();
    SimpleDateFormat sd = new SimpleDateFormat("MMMM dd, YYYY");
    SimpleDateFormat sd1 = new SimpleDateFormat("HH:mm");

    String s = sd.format(d);
    String s1 = sd1.format(d);

    System.out.println(s + " " + s1);
  }
}

The code above generates the following result.