
SimpleDateFormat vs DateTimeFormatter表格对比项SimpleDateFormat(JDK1.1)DateTimeFormatter(JDK8)所属包java.text.SimpleDateFormatjava.time.format.DateTimeFormatter线程安全❌非线程安全绝对不能定义为 static 成员变量多线程并发 parse/format 会乱码、抛异常、返回错误时间✅线程安全可以定义为public static final常量多线程随便用处理类型java.util.DateLocalDateTime / LocalDate / ZonedDateTimejava.time 新时间类异常parse()抛出受检异常 ParseException必须 try‑catchparse()抛出运行时异常 DateTimeException可不强制 catch时区 / Locale默认取 JVM 系统默认时区、默认 Locale容易受服务器环境影响可以显式指定时区、Locale可控性强对象开销如果做成局部变量每次 new 对象有小对象创建开销静态常量只实例化一次开销极小格式化输出format(Date)parse(String) → Dateformat (时间对象)parse (String) → 新时间对象