Convert java.util.Date to String

前端 未结 18 2508
悲&欢浪女
悲&欢浪女 2020-11-22 05:37

I want to convert a java.util.Date object to a String in Java.

The format is 2010-05-30 22:15:52

18条回答
  •  野性不改
    2020-11-22 05:59

    One Line option

    This option gets a easy one-line to write the actual date.

    Please, note that this is using Calendar.class and SimpleDateFormat, and then it's not logical to use it under Java8.

    yourstringdate =  new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime());
    

提交回复
热议问题