Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ helpviewer_keywords:
- "formatting [.NET], time"
- "date and time strings"
ms.assetid: 98b374e3-0cc2-4c78-ab44-efb671d71984
ai-usage: ai-assisted
---

# Custom date and time format strings
Expand Down Expand Up @@ -341,6 +342,9 @@ The following example includes the "H" custom format specifier in a custom forma

The "HH" custom format specifier (plus any number of additional "H" specifiers) represents the hour as a number from 00 to 23; that is, the hour is represented by a zero-based 24-hour clock that counts the hours since midnight. A single-digit hour is formatted with a leading zero.

> [!NOTE]
> Don't combine "HH" or "H" with the "t" or "tt" AM/PM designator specifier in a parsing format string. The 24-hour clock is incompatible with the AM/PM designator in parsing operations, and throws a <xref:System.FormatException>. Use "h" or "hh" instead.

The following example includes the "HH" custom format specifier in a custom format string.

[!code-csharp[Formatting.DateAndTime.Custom#10](~/samples/snippets/csharp/VS_Snippets_CLR/Formatting.DateAndTime.Custom/cs/Custom1.cs#10)]
Expand Down Expand Up @@ -492,6 +496,9 @@ The "tt" custom format specifier (plus any number of additional "t" specifiers)

Make sure to use the "tt" specifier for languages for which it's necessary to maintain the distinction between AM and PM. An example is Japanese, for which the AM and PM designators differ in the second character instead of the first character.

> [!NOTE]
> When you parse a string that includes an AM/PM designator, use the "h" or "hh" hour specifier (12-hour clock) instead of "H" or "HH" (24-hour clock). The 24-hour clock specifier is incompatible with the AM/PM designator in a parsing operation, and throws a <xref:System.FormatException>.

The following example includes the "tt" custom format specifier in a custom format string.

[!code-csharp[Formatting.DateAndTime.Custom#8](~/samples/snippets/csharp/VS_Snippets_CLR/Formatting.DateAndTime.Custom/cs/Custom1.cs#8)]
Expand Down