Java SimpleDateFormat format date to String like "2020/02/24" (forward slash)

Description

Java SimpleDateFormat format date to String like "2020/02/24" (forward slash)

import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
  public static void main(String[] argv) {
    Date date = new Date();
    System.out.println(DateStr(date));
  }/*from w w  w . ja  v  a 2 s.  c  o  m*/

  public static String DateStr(Date date) {
    SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");

    String timeStr = format.format(date);
    return timeStr;
  }
}



PreviousNext

Related