Java Calendar format to String like "02/24/20 04:55:21"

Description

Java Calendar format to String like "02/24/20 04:55:21"

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main {

  public static void main(String[] args) {
    // Create new calendar
    Calendar cal = Calendar.getInstance();

    // Create instance of SimpleDateFormat class using pattern
    SimpleDateFormat dateFormatter1 = new SimpleDateFormat("MM/dd/YY hh:mm:ss");
    String result = null;/*from   www.  j  av  a  2 s  . c  o  m*/

    result = dateFormatter1.format(cal.getTime());
    System.out.println(result);


  }
}



PreviousNext

Related