Tagged articles
SimpleDateFormat
27 articles · Page 1 of 1
This guide covers Java date/time handling from legacy Date and SimpleDateFormat to modern JDK 8+ APIs including LocalDateTime, DateTimeFormatter, Period, and Duration with practical code examples and conversion techniques.
DATETIMEDateTimeFormatterDuration
0 likes · 14 min read

The article explains that in Java's SimpleDateFormat the lowercase y pattern (year‑of‑era) should be used for calendar dates, because the uppercase Y pattern represents a week‑based year which can incorrectly roll over to the next year near year‑end, causing bugs.
JavaSimpleDateFormatbug
0 likes · 4 min read

This article explains how using 'YYYY' instead of 'yyyy' in Java's SimpleDateFormat can cause year miscalculations, especially around year-end weeks, demonstrates the issue with sample code, shows correct usage, and warns developers to avoid this subtle bug.
JavaSimpleDateFormatYear
0 likes · 4 min read

A Java date‑formatting bug occurs when the week‑based year pattern 'YYYY' is used instead of the calendar year 'yyyy', causing dates near year‑end to display the next year, and this article explains the cause, demonstrates it with code, and shows how to avoid it.
BackendSimpleDateFormatYYYY
0 likes · 4 min read

This article presents several common solutions for addressing the thread‑safety problem of Java's SimpleDateFormat in high‑concurrency environments, including using local variables, synchronized blocks, Lock, ThreadLocal, Java 8 DateTimeFormatter, and Joda‑Time, and evaluates their performance and suitability.
ConcurrencyDateTimeFormatterJava
0 likes · 17 min read

This article explains why Java's SimpleDateFormat is not thread‑safe, demonstrates the concurrency problem with a multithreaded demo, and presents three solutions—creating new instances, synchronizing access, and using ThreadLocal—highlighting the ThreadLocal approach with code examples and discussion of potential memory‑leak considerations.
ConcurrencySimpleDateFormatThreadLocal
0 likes · 4 min read

An operation team discovered that QR code redirects returned 404 due to expired access tokens, traced to SimpleDateFormat’s thread‑unsafe parsing causing incorrect expiration dates; the article analyzes the root cause, demonstrates failing multithreaded tests, and presents four thread‑safe alternatives including local instances, synchronization, ThreadLocal, and Java 8’s DateTimeFormatter.
ConcurrencyDateTimeFormatterJava
0 likes · 10 min read

This article compares three common Java date‑time formatting approaches—SimpleDateFormat, Java 8’s DateTimeFormatter, and Apache Commons Lang3’s DateFormatUtils—examines thread‑safety issues, provides code examples, and offers conversion utilities between Date, LocalDate, and LocalDateTime for robust backend development.
Apache CommonsDATETIMEDateTimeFormatter
0 likes · 9 min read

This article lists ten frequent mistakes when using Java's date and time APIs—such as misusing Calendar fields, wrong format patterns, thread‑unsafe SimpleDateFormat, and daylight‑saving quirks—and provides clear corrected examples and best‑practice solutions.
DateSimpleDateFormatcalendar
0 likes · 12 min read

This article explains why SimpleDateFormat.parse() and SimpleDateFormat.format() are not thread‑safe in Java, analyzes the underlying causes involving shared Calendar objects, and presents three practical solutions—including per‑thread instances, synchronized blocks, and ThreadLocal usage—to eliminate concurrency bugs.
Date ParsingSimpleDateFormatSynchronization
0 likes · 11 min read

This article explains the subtle difference between 'yyyy' and 'YYYY' in Java's SimpleDateFormat, demonstrates how using the wrong pattern can cause year miscalculations—especially on December 31st—and provides code examples and a clear explanation to help developers avoid this common bug.
BackendJavaSimpleDateFormat
0 likes · 4 min read

The article explains how using the week‑based year pattern (YYYY) instead of the calendar year pattern (yyyy) in Java's SimpleDateFormat can cause dates like 2019‑12‑31 to be displayed as 2020‑12‑31, illustrating the issue with code examples and a clear explanation of the underlying rules.
BackendJavaSimpleDateFormat
0 likes · 4 min read

The article explains why using the pattern 'YYYY‑MM‑dd' with Java's SimpleDateFormat can produce an incorrect year for dates near the end of the year, demonstrates the issue with a unit test comparing it to the correct 'yyyy‑MM‑dd' pattern, and reveals that the problem stems from the week‑based year semantics of 'Y'.
JavaSimpleDateFormatbug
0 likes · 5 min read

The article explains a mysterious Java date‑formatting bug where parsing "1900-01-01 08:00:00" with SimpleDateFormat yields "1900-01-01 08:05:43", tracing the cause to historic Shanghai timezone offsets and changes in the IANA TZ database across JDK versions.
DATETIMEJDK bugJava
0 likes · 9 min read

An intriguing Java date‑parsing bug shows a 5 minute 43 second offset when formatting the year 1900, caused by historic Shanghai timezone offsets and changes in the TZDB; the article walks through code examples, bug reports, and the evolution of timezone data that explain this anomaly.
JDK bugSimpleDateFormatTZDB
0 likes · 9 min read

This article explains why SimpleDateFormat is not thread‑safe in Java, demonstrates the problem with multithreaded examples, and presents five practical solutions—including local variables, synchronized blocks, explicit locks, ThreadLocal, and the modern DateTimeFormatter—along with their advantages and drawbacks.
ConcurrencyDateTimeFormatterJava
0 likes · 13 min read

This article demonstrates how the week‑based year pattern "YYYY" in Java's SimpleDateFormat can incorrectly roll over the year for dates near year‑end, provides a reproducible unit test with code and output, and explains the underlying reason behind the discrepancy.
SimpleDateFormatdate-formattingweek-based-year
0 likes · 4 min read

This article explains why a static SimpleDateFormat instance is not thread‑safe, demonstrates the issue with concurrent parsing, and provides a ThreadLocal‑based solution with complete Java code examples and performance observations.
SimpleDateFormatdate-formattingthread-safety
0 likes · 10 min read

This article explains how to use Java's SimpleDateFormat for date‑time formatting and parsing, describes the pattern letters, clarifies the difference between "yyyy" and "YYYY" for week‑year calculations, and shows how ISO 8601 week definitions are supported in Java with practical code examples.
ISO 8601SimpleDateFormatdate-formatting
0 likes · 8 min read

This article explains why using uppercase YYYY or DD in Java date‑format patterns can produce incorrect results around year boundaries, demonstrates the bugs with concrete code examples, and clarifies the correct usage of lowercase yyyy and dd for calendar dates.
SimpleDateFormatYYYYbug
0 likes · 6 min read

Around the 2020 New Year many Java applications displayed dates like 2020/12/31 due to a subtle bug in SimpleDateFormat when using the pattern "YYYY" instead of "yyyy", which can be reproduced, explained, and resolved with a simple pattern change.
DateBugJavaSimpleDateFormat
0 likes · 8 min read

This article explains why Java's SimpleDateFormat is not thread‑safe, demonstrates the resulting concurrency errors, and presents four practical solutions—including per‑call instantiation, ThreadLocal, Apache FastDateFormat, and Java 8's Instant with DateTimeFormatter—along with JMH benchmark results comparing their performance across JDK 8 and JDK 11.
SimpleDateFormatThreadLocaldateformat
0 likes · 7 min read

This article explains why Java's SimpleDateFormat is not thread‑safe, demonstrates the problem with multithreaded examples, and presents two robust solutions—using ThreadLocal or the Java 8 immutable date‑time API—to ensure correct date formatting in concurrent environments.
SimpleDateFormatdate-time APIjava-8
0 likes · 6 min read

This article explains why the classic Java SimpleDateFormat class is not thread‑safe, demonstrates the problems caused by using a static instance in concurrent code, and presents four practical solutions—including creating new instances, synchronizing, using ThreadLocal, and switching to the immutable DateTimeFormatter.
DateTimeFormatterJavaSimpleDateFormat
0 likes · 8 min read

This article explains why Java's SimpleDateFormat is not thread‑safe, demonstrates the problems caused by using a static instance in multithreaded code, and presents four practical solutions—including synchronized blocks, ThreadLocal, and the modern DateTimeFormatter—to ensure correct date handling.
DateTimeFormatterJavaSimpleDateFormat
0 likes · 5 min read

This article narrates a step‑by‑step investigation of a Java server whose heap memory exceeded 95%, detailing log collection, tool usage, thread analysis, and ultimately uncovering a thread‑unsafe SimpleDateFormat that caused an infinite loop and massive memory consumption.
JavaSimpleDateFormatheap memory
0 likes · 15 min read

This article explains the legacy java.util.Date class, its limited useful constructors and methods, the more flexible java.util.Calendar API, how to format and parse dates with DateFormat and SimpleDateFormat, and best practices for storing timestamps in databases using long values.
DateSimpleDateFormatcalendar
0 likes · 9 min read
