首页  

时间格式化性能对比     所属分类 java 浏览量 688
SimpleDateFormat 非线程安全
可以clone 或直接使用 apache commons FastDateFormat

3种方式的耗时对比 (ms)
直接new SimpleDateFormat
clone SimpleDateFormat
使用 FastDateFormat

推荐使用 FastDateFormat

2507 1059 569
1583 890 514
1314 846 505
1303 843 505
1370 846 500
1398 961 551
1564 1319 672
1558 1220 633
1531 1045 553

完整测试代码
https://gitee.com/dyyx/springboothello/blob/master/src/test/java/dyyx/DateFormatPerfTest.java


最新加入 LocalDateTime 测试 ,看起来最快 不过 LocalDateTime 对 格式要求比较严格 java.time.format.DateTimeParseException: Text '2021-12-08 00:00:0' could not be parsed at index 17 少一位会报错 2004 889 518 911 1240 730 468 429 1154 736 475 430 1150 740 485 434 1353 768 489 434 1295 826 533 434 1296 738 474 431 1170 766 489 442 1183 747 545 480 1319 799 529 455 1386 755 544 462 1350 920 492 473 1163 799 531 482
SimpleDateFormat并发问题实例演示

上一篇     下一篇
千字文原文

中国历史上的两个短命王朝

JDK默认GC

jackson与SimpleDateFormat

中国简史

网络流行语