Skip to content

Commit df8c9ef

Browse files
Copilotbrunoborges
andcommitted
Keep yyyy-MM-dd for SimpleDateFormat, uuuu-MM-dd only for DateTimeFormatter
Co-authored-by: brunoborges <129743+brunoborges@users.noreply.github.com>
1 parent 3fa3d81 commit df8c9ef

File tree

6 files changed

+6
-6
lines changed

6 files changed

+6
-6
lines changed

data/snippets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2424,7 +2424,7 @@
24242424
"modernLabel": "Java 8+",
24252425
"oldApproach": "SimpleDateFormat",
24262426
"modernApproach": "DateTimeFormatter",
2427-
"oldCode": "// Not thread-safe!\nSimpleDateFormat sdf =\n new SimpleDateFormat(\"uuuu-MM-dd\");\nString formatted = sdf.format(date);\n// Must synchronize for concurrent use",
2427+
"oldCode": "// Not thread-safe!\nSimpleDateFormat sdf =\n new SimpleDateFormat(\"yyyy-MM-dd\");\nString formatted = sdf.format(date);\n// Must synchronize for concurrent use",
24282428
"modernCode": "DateTimeFormatter fmt =\n DateTimeFormatter.ofPattern(\n \"uuuu-MM-dd\");\nString formatted =\n LocalDate.now().format(fmt);\n// Thread-safe, immutable",
24292429
"summary": "Format dates with thread-safe, immutable DateTimeFormatter.",
24302430
"explanation": "DateTimeFormatter is immutable and thread-safe, unlike SimpleDateFormat. It can be stored as a constant and shared. Predefined formatters like ISO_LOCAL_DATE are available for common formats.",

date-formatting.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ <h1>Date formatting</h1>
125125
<div class="compare-code">
126126
<pre class="code-text">// Not thread-safe!
127127
SimpleDateFormat sdf =
128-
new SimpleDateFormat(&quot;uuuu-MM-dd&quot;);
128+
new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);
129129
String formatted = sdf.format(date);
130130
// Must synchronize for concurrent use</pre>
131131
</div>

duration-and-period.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ <h3>Date formatting</h3>
254254
<div class="mini-label">Pre-Java 8</div>
255255
<pre class="code-text">// Not thread-safe!
256256
SimpleDateFormat sdf =
257-
new SimpleDateFormat(&quot;uuuu-MM-dd&quot;);
257+
new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);
258258
String formatted = sdf.format(date);
259259
// Must synchronize for concurrent use</pre>
260260
</div>

hex-format.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ <h3>Date formatting</h3>
220220
<div class="mini-label">Pre-Java 8</div>
221221
<pre class="code-text">// Not thread-safe!
222222
SimpleDateFormat sdf =
223-
new SimpleDateFormat(&quot;uuuu-MM-dd&quot;);
223+
new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);
224224
String formatted = sdf.format(date);
225225
// Must synchronize for concurrent use</pre>
226226
</div>

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2516,7 +2516,7 @@ <h3>Date formatting</h3>
25162516
<span class="mini-label">Old</span>
25172517
<span class="code-text">// Not thread-safe!
25182518
SimpleDateFormat sdf =
2519-
new SimpleDateFormat(&quot;uuuu-MM-dd&quot;);
2519+
new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);
25202520
String formatted = sdf.format(date);
25212521
// Must synchronize for concurrent use</span>
25222522
</div>

java-time-basics.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ <h3>Date formatting</h3>
286286
<div class="mini-label">Pre-Java 8</div>
287287
<pre class="code-text">// Not thread-safe!
288288
SimpleDateFormat sdf =
289-
new SimpleDateFormat(&quot;uuuu-MM-dd&quot;);
289+
new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);
290290
String formatted = sdf.format(date);
291291
// Must synchronize for concurrent use</pre>
292292
</div>

0 commit comments

Comments
 (0)