Java SimpleDateFormat format date to String like "2020-02-24"
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 .j a v a 2s . c om public static String DateStr(Date date) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); String timeStr = format.format(date); return timeStr; } }