如何使用 SimpleDateFormat 类的 format(date) 方法来格式化时间,如下所示:
package csdn1; import java.text.SimpleDateFormat; import java.util.Date; public class 时间csdn1 { public static void main(String[] args){ Date date = new Date(); String strDateFormat = "yyyy-MM-dd HH:mm:ss"; SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat); System.out.println(sdf.format(date)); } }
运行结果为:
2020-03-23 15:43:23