格式化当前时间 package com.ycy2; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Test01 { public static void main(String[] args) { Date date = new Date(); System.out.println(date); long time = date.getTime(); System.out.println(time); String pattern = "yyyy-MM-dd HH:mm:ss"; Locale locale= Locale.getDefault(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern, locale); String format = simpleDateFormat.format(date); System.out.println(format); } }