Java Date format to String like "2020-02-24 11:38:50"
import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static void main(String[] argv) { System.out.println(getCurrentFormatDate()); }/*from ww w .j a v a 2s.c o m*/ public static String getCurrentFormatDate() { Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); String datetime = sdf.format(date); return datetime; } }