CINXE.COM

Custom date and time format strings - .NET | Microsoft Learn

<!DOCTYPE html><html class="hasSidebar hasPageActions hasBreadcrumb conceptual has-default-focus theme-light" lang="en-us" dir="ltr" data-authenticated="false" data-auth-status-determined="false" data-target="docs" x-ms-format-detection="none"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta property="og:title" content="Custom date and time format strings - .NET" /> <meta property="og:type" content="website" /> <meta property="og:url" content="https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings" /><meta property="og:description" content="Learn to use custom date and time format strings to convert DateTime or DateTimeOffset values into text representations, or to parse strings for dates &amp; times." /><meta property="og:image" content="https://learn.microsoft.com/dotnet/media/dot-net-cross-platform.png" /> <meta property="og:image:alt" content="Custom date and time format strings - .NET | Microsoft Learn" /> <meta name="twitter:card" content="summary" /> <meta name="twitter:site" content="@MicrosoftLearn" /> <meta name="color-scheme" content="light dark"><meta name="apiPlatform" content="dotnet" /> <meta name="author" content="adegeo" /> <meta name="breadcrumb_path" content="/dotnet/breadcrumb/toc.json" /> <meta name="depot_name" content="VS.core-docs" /> <meta name="description" content="Learn to use custom date and time format strings to convert DateTime or DateTimeOffset values into text representations, or to parse strings for dates &amp; times." /> <meta name="document_id" content="dda93f14-f1b5-fde6-e441-302cdac261ab" /> <meta name="document_version_independent_id" content="96abc7c4-3719-82da-e271-881d62f0640f" /> <meta name="feedback_help_link_type" content="" /> <meta name="feedback_help_link_url" content="" /> <meta name="feedback_product_url" content="https://aka.ms/feedback/report?space=61" /> <meta name="feedback_system" content="OpenSource" /> <meta name="git_commit_id" content="02edf1c2c9c9dced394e3eccf7dd2b09f8fef0f0" /> <meta name="gitcommit" content="https://github.com/dotnet/docs/blob/02edf1c2c9c9dced394e3eccf7dd2b09f8fef0f0/docs/standard/base-types/custom-date-and-time-format-strings.md" /> <meta name="interactive_type" content="csharp" /> <meta name="locale" content="en-us" /> <meta name="ms.assetid" content="98b374e3-0cc2-4c78-ab44-efb671d71984" /> <meta name="ms.author" content="adegeo" /> <meta name="ms.date" content="05/12/2022" /> <meta name="ms.devlang" content="dotnet" /> <meta name="ms.service" content="dotnet-fundamentals" /> <meta name="ms.topic" content="reference" /> <meta name="original_content_git_url" content="https://github.com/dotnet/docs/blob/live/docs/standard/base-types/custom-date-and-time-format-strings.md" /> <meta name="page_type" content="conceptual" /> <meta name="pdf_url_template" content="https://learn.microsoft.com/pdfstore/en-us/VS.core-docs/{branchName}{pdfName}" /> <meta name="schema" content="Conceptual" /> <meta name="search.mshattr.devlang" content="csharp vb" /> <meta name="show_latex" content="true" /> <meta name="site_name" content="Docs" /> <meta name="toc_rel" content="../../fundamentals/toc.json" /> <meta name="uhfHeaderId" content="MSDocsHeader-DotNet" /> <meta name="updated_at" content="2024-09-10 08:29 AM" /> <meta name="word_count" content="11477" /> <meta name="persistent_id" content="58fb1aa0-4c4c-dd6c-590b-194d21204c54" /> <meta name="cmProducts" content="https://authoring-docs-microsoft.poolparty.biz/devrel/bcbcbad5-4208-4783-8035-8481272c98b8" data-source="generated" /> <meta name="cmProducts" content="https://authoring-docs-microsoft.poolparty.biz/devrel/7696cda6-0510-47f6-8302-71bb5d2e28cf" data-source="generated" /> <meta name="spProducts" content="https://authoring-docs-microsoft.poolparty.biz/devrel/43b2e5aa-8a6d-4de2-a252-692232e5edc8" data-source="generated" /> <meta name="spProducts" content="https://authoring-docs-microsoft.poolparty.biz/devrel/69c76c32-967e-4c65-b89a-74cc527db725" data-source="generated" /> <meta name="scope" content=".NET" /><meta name="github_feedback_content_git_url" content="https://github.com/dotnet/docs/blob/main/docs/standard/base-types/custom-date-and-time-format-strings.md" /><link href="https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings" rel="canonical"><title>Custom date and time format strings - .NET | Microsoft Learn</title><link rel="stylesheet" href="/static/assets/0.4.028726178/styles/site-ltr.css"> <script id="msdocs-script"> var msDocs = {environment: { supportLevel: 'production', accessLevel: 'online', reviewFeatures: false, systemContent: true, azurePortalHostname: 'portal.azure.com', legacyHosting: false, siteName: 'learn', },data: { timeOrigin: Date.now(), contentLocale: 'en-us', contentDir: 'ltr', userLocale: 'en-us', userDir: 'ltr', pageTemplate: 'Conceptual', brand: '', context: {}, hasBinaryRating: true, feedbackHelpLinkType:'', feedbackHelpLinkUrl:'', standardFeedback: false, showFeedbackReport: false, enableTutorialFeedback: false, feedbackSystem: 'OpenSource', feedbackGitHubRepo: 'dotnet/docs', feedbackProductUrl: 'https://aka.ms/feedback/report?space=61',extendBreadcrumb: false,isEditDisplayable: true, hideViewSource: false, hasPageActions: true, hasPrintButton: true, hasBookmark: true, hasShare: true, isPermissioned: false, isPrivateUnauthorized: false,hasRecommendations: true,openSourceFeedback: true, openSourceFeedbackIssueUrl: 'https://github.com/dotnet/docs/issues/new?template=z-customer-feedback.yml', openSourceFeedbackIssueTitle: '', openSourceFeedbackIssueLabels: '',contributors: [{ name: "adegeo", url: "https://github.com/adegeo" },{ name: "geniuszxy", url: "https://github.com/geniuszxy" },{ name: "technatoria", url: "https://github.com/technatoria" },{ name: "JJLovesLife", url: "https://github.com/JJLovesLife" },{ name: "gewarren", url: "https://github.com/gewarren" },{ name: "tdykstra", url: "https://github.com/tdykstra" },{ name: "nschonni", url: "https://github.com/nschonni" },{ name: "BillWagner", url: "https://github.com/BillWagner" },{ name: "DCtheGeek", url: "https://github.com/DCtheGeek" },{ name: "IEvangelist", url: "https://github.com/IEvangelist" },{ name: "DennisLee-DennisLee", url: "https://github.com/DennisLee-DennisLee" },{ name: "nxtn", url: "https://github.com/nxtn" },{ name: "Thraka", url: "https://github.com/Thraka" },{ name: "AndreyAkinshin", url: "https://github.com/AndreyAkinshin" },{ name: "mairaw", url: "https://github.com/mairaw" },{ name: "svick", url: "https://github.com/svick" },{ name: "v-makoud", url: "https://github.com/v-makoud" },{ name: "nemrism", url: "https://github.com/nemrism" },{ name: "OpportunityLiu", url: "https://github.com/OpportunityLiu" },{ name: "ChrisMaddock", url: "https://github.com/ChrisMaddock" },{ name: "Mikejo5000", url: "https://github.com/Mikejo5000" },{ name: "mjhoffman65", url: "https://github.com/mjhoffman65" },{ name: "mattjohnsonpint", url: "https://github.com/mattjohnsonpint" },{ name: "guardrex", url: "https://github.com/guardrex" },{ name: "yishengjin1413", url: "https://github.com/yishengjin1413" },{ name: "tompratt-AQ", url: "https://github.com/tompratt-AQ" }],mathjax: {},}, functions:{} }; </script><script src="https://wcpstatic.microsoft.com/mscc/lib/v2/wcp-consent.js"></script> <script src="https://js.monitor.azure.com/scripts/c/ms.jsll-4.min.js"></script><script src="/static/assets/0.4.028726178/global/deprecation.js"></script><script src="/static/assets/0.4.028726178/scripts/en-us/index-docs.js"></script></head> <body lang="en-us" dir="ltr"> <div class="header-holder has-default-focus"> <a href="#main" style="z-index: 1070" class="outline-color-text visually-hidden-until-focused position-fixed inner-focus focus-visible top-0 left-0 right-0 padding-xs text-align-center has-body-background" tabindex="1">Skip to main content</a><div hidden id="cookie-consent-holder" data-test-id="cookie-consent-container"></div> <div id="unsupported-browser" style=" background-color: white; color: black; padding: 16px; border-bottom: 1px solid grey;" hidden > <div style="max-width: 800px; margin: 0 auto;"> <p style="font-size: 24px">This browser is no longer supported.</p> <p style="font-size: 16px; margin-top: 16px;">Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.</p> <div style="margin-top: 12px;"> <a href="https://go.microsoft.com/fwlink/p/?LinkID=2092881 " style=" background-color: #0078d4; border: 1px solid #0078d4; color: white; padding: 6px 12px; border-radius: 2px; display: inline-block; ">Download Microsoft Edge</a> <a href="https://learn.microsoft.com/en-us/lifecycle/faq/internet-explorer-microsoft-edge" style=" background-color: white; padding: 6px 12px; border: 1px solid #505050; color: #171717; border-radius: 2px; display: inline-block; ">More info about Internet Explorer and Microsoft Edge</a> </div> </div> </div> <!-- liquid-tag banners global --> <!-- site header --> <header id="ms--site-header" data-test-id="site-header-wrapper" role="banner" itemscope="itemscope" itemtype="http://schema.org/Organization"> <div id="ms--mobile-nav" class="site-header display-none-tablet padding-inline-none gap-none" data-bi-name="mobile-header" data-test-id="mobile-header"></div> <div id="ms--primary-nav" class="site-header display-none display-flex-tablet" data-bi-name="L1-header" data-test-id="primary-header"></div> <div id="ms--secondary-nav" class="site-header display-none display-flex-tablet" data-bi-name="L2-header" data-test-id="secondary-header"></div> </header><div id="content-header" class="content-header uhf-container has-padding has-default-focus border-bottom-none" data-bi-name="content-header"> <div class="content-header-controls margin-xxs margin-inline-sm-tablet"> <button type="button" class="contents-button button button-sm margin-right-xxs" data-bi-name="contents-expand" aria-haspopup="true" data-contents-button> <span class="icon"><span class="docon docon-menu" aria-hidden="true"></span></span> <span class="contents-expand-title">Table of contents</span> </button> <button type="button" class="ap-collapse-behavior ap-expanded button button-sm" data-bi-name="ap-collapse" aria-controls="action-panel"> <span class="icon"><span class="docon docon-exit-mode" aria-hidden="true"></span></span> <span>Exit focus mode</span> </button> </div> </div><div id="disclaimer-holder" class="has-overflow-hidden has-default-focus"> <!-- liquid-tag banners sectional --> </div> </div> <div class="mainContainer uhf-container has-default-focus" data-bi-name="body"> <div class="columns has-large-gaps is-gapless-mobile "><div id="left-container" class="left-container is-hidden-mobile column is-one-third-tablet is-one-quarter-desktop"> <nav id="affixed-left-container" class="margin-top-sm-tablet position-sticky display-flex flex-direction-column" aria-label="Primary"></nav> </div><!-- .primary-holder --> <section class="primary-holder column is-two-thirds-tablet is-three-quarters-desktop"> <!--div.columns --> <div class="columns is-gapless-mobile has-large-gaps "><div id="main-column" class="column is-full is-8-desktop"> <main id="main" class="" role="main" data-bi-name="content" lang="en-us" dir="ltr"><!-- article-header --> <div id="article-header" class="background-color-body margin-top-sm-tablet margin-bottom-xs display-none-print"> <div class="display-flex align-items-center "><details id="article-header-breadcrumbs-overflow-popover" class="popover" data-for="article-header-breadcrumbs"> <summary class="button button-clear button-primary button-sm inner-focus" aria-label="All breadcrumbs"> <span class="icon"> <span class="docon docon-more"></span> </span> </summary> <div id="article-header-breadcrumbs-overflow" class="popover-content padding-none"> </div> </details> <bread-crumbs id="article-header-breadcrumbs" data-test-id="article-header-breadcrumbs" class="overflow-hidden flex-grow-1 margin-right-sm margin-right-md-tablet margin-right-lg-desktop margin-left-negative-xxs padding-left-xxs"></bread-crumbs><div id="article-header-page-actions" class="opacity-none margin-left-auto display-flex flex-wrap-no-wrap align-items-stretch"><div class="language dropdown display-flex align-items-center"> <button class="dropdown-trigger button button-clear button-sm button-primary" aria-controls="language-menu" aria-expanded="false" title="Language" data-bi-name="language"> <span class="lang-title align-self-flex-start" dir="ltr">Language</span> <span class="icon" aria-hidden="true"> <span class="docon docon-chevron-down-light expanded-indicator"></span> </span> </button> <div class="dropdown-menu padding-xxs language-selector" name="language-selector" role="menu"> <ul data-bi-name="language-links" dir="ltr"><li> <a class="button button-clear button-sm button-block" data-bi-name="lang-csharp" tabindex="0" aria-selected="false"></a> </li><li> <a class="button button-clear button-sm button-block" data-bi-name="lang-vb" tabindex="0" aria-selected="false"></a> </li></ul> </div> </div><a id="lang-link-tablet" class="button button-primary button-clear button-sm display-none display-inline-flex-tablet" title="Read in English" data-bi-name="language-toggle" data-read-in-link hidden> <span class="icon margin-none" aria-hidden="true" data-read-in-link-icon> <span class="docon docon-locale-globe"></span> </span> <span class="is-visually-hidden" data-read-in-link-text>Read in English</span> </a><button type="button" class="collection button button-clear button-sm button-primary display-none display-inline-flex-tablet" data-list-type="collection" data-bi-name="collection" title="Add to collection"> <span class="icon margin-none" aria-hidden="true"> <span class="docon docon-circle-addition"></span> </span> <span class="collection-status is-visually-hidden">Save</span> </button><a data-contenteditbtn class="button button-clear button-sm text-decoration-none button-primary display-none display-inline-flex-tablet" aria-label="Edit" title="Edit This Document" data-bi-name="edit" href="https://github.com/dotnet/docs/blob/main/docs/standard/base-types/custom-date-and-time-format-strings.md" data-original_content_git_url="https://github.com/dotnet/docs/blob/live/docs/standard/base-types/custom-date-and-time-format-strings.md" data-original_content_git_url_template="{repo}/blob/{branch}/docs/standard/base-types/custom-date-and-time-format-strings.md" data-pr_repo="" data-pr_branch=""> <span class="icon margin-none" aria-hidden="true"> <span class="docon docon-edit-outline"></span> </span> </a> <details class="popover popover-right" id="article-header-page-actions-overflow"> <summary class="justify-content-flex-start button button-clear button-sm button-primary" aria-label="More actions" title="More actions"> <span class="icon" aria-hidden="true"> <span class="docon docon-more-vertical"></span> </span> </summary> <div class="popover-content padding-xs"><button data-page-action-item="overflow-mobile" type="button" class="justify-content-flex-start button-block button-sm has-inner-focus button button-clear display-none-tablet" data-bi-name="contents-expand" data-contents-button data-popover-close> <span class="icon"> <span class="docon docon-editor-list-bullet" aria-hidden="true"></span> </span><span class="contents-expand-title">Table of contents</span></button><a id="lang-link-overflow" class="justify-content-flex-start button-sm has-inner-focus button button-clear button-block display-none-tablet" title="Read in English" data-bi-name="language-toggle" data-page-action-item="overflow-mobile" data-check-hidden="true" data-read-in-link hidden > <span class="icon" aria-hidden="true" data-read-in-link-icon> <span class="docon docon-locale-globe"></span> </span> <span data-read-in-link-text>Read in English</span> </a><button type="button" class="collection justify-content-flex-start button button-clear button-sm has-inner-focus button-block display-none-tablet" data-list-type="collection" data-bi-name="collection" title="Save" data-page-action-item="overflow-mobile" data-check-hidden="true" data-popover-close> <span class="icon" aria-hidden="true"> <span class="docon docon-circle-addition"></span> </span> <span class="collection-status">Save</span> </button> <button type="button" class="collection justify-content-flex-start button button-clear button-sm has-inner-focus button-block display-none-tablet" data-list-type="plan" data-bi-name="plan" title="Add to Plan" data-page-action-item="overflow-mobile" data-check-hidden="true" data-popover-close hidden> <span class="icon" aria-hidden="true"> <span class="docon docon-circle-addition"></span> </span> <span class="plan-status">Add to Plan</span> </button><a data-contenteditbtn class="button button-clear button-block button-sm has-inner-focus justify-content-flex-start text-decoration-none display-none-tablet" aria-label="Edit" title="Edit This Document" data-bi-name="edit" href="https://github.com/dotnet/docs/blob/main/docs/standard/base-types/custom-date-and-time-format-strings.md" data-original_content_git_url="https://github.com/dotnet/docs/blob/live/docs/standard/base-types/custom-date-and-time-format-strings.md" data-original_content_git_url_template="{repo}/blob/{branch}/docs/standard/base-types/custom-date-and-time-format-strings.md" data-pr_repo="" data-pr_branch=""> <span class="icon" aria-hidden="true"> <span class="docon docon-edit-outline"></span> </span> <span>Edit</span> </a><div aria-hidden="true" class="margin-none" data-page-action-item="overflow-all"></div> <hr class="display-none-tablet margin-bottom-xxs margin-top-xxs" /> <h4 class="font-size-sm padding-left-xxs">Share via</h4> <a class="button button-clear button-sm button-block has-inner-focus text-decoration-none justify-content-flex-start share-facebook" data-bi-name="facebook" data-page-action-item="overflow-all"> <span class="icon" aria-hidden="true"> <span class="docon docon-facebook-share font-size-md color-primary"></span> </span> <span class="margin-left-xxs">Facebook</span> </a> <a class="button button-clear button-sm has-inner-focus button-block text-decoration-none justify-content-flex-start share-twitter" data-bi-name="twitter" data-page-action-item="overflow-all"> <span class="icon" aria-hidden="true"> <span class="docon docon-xlogo-share font-size-xxs"></span> </span> <span class="margin-left-xxs">x.com</span> </a> <a class="button button-clear button-sm has-inner-focus button-block text-decoration-none justify-content-flex-start share-linkedin" data-bi-name="linkedin" data-page-action-item="overflow-all"> <span class="icon" aria-hidden="true"> <span class="docon docon-linked-in-logo font-size-sm color-primary"></span> </span> <span class="margin-left-xxs">LinkedIn</span> </a> <a class="button button-clear button-sm button-block has-inner-focus text-decoration-none justify-content-flex-start margin-bottom-xxs share-email" data-bi-name="email" data-page-action-item="overflow-all"> <span class="icon" aria-hidden="true"> <span class="docon docon-mail-message font-size-sm color-primary"></span> </span> <span class="margin-left-xxs">Email</span> </a><hr /> <button class="button button-block button-clear button-sm justify-content-flex-start has-inner-focus margin-top-xxs" title="Print" type="button" aria-label="Print" data-bi-name="print" data-page-action-item="overflow-all" data-popover-close data-print-page data-check-hidden="true"> <span class="icon" aria-hidden="true"> <span class="docon docon-print font-size-sm color-primary"></span> </span> <span class="margin-left-xxs">Print</span> </button> </div> </details> </div></div> </div> <!-- end article-header --><div> <button type="button" class="border contents-button button button-clear button-sm is-hidden-tablet has-inner-focus" data-bi-name="contents-expand" data-contents-button hidden> <span class="icon"> <span class="docon docon-editor-list-bullet" aria-hidden="true"></span> </span><span class="contents-expand-title">Table of contents</span></button> </div><!-- end mobile-contents button --> <div class="content "><h1 id="custom-date-and-time-format-strings">Custom date and time format strings</h1><div class="display-flex justify-content-space-between align-items-center flex-wrap-wrap page-metadata-container"> <div class="margin-right-xxs"> <ul class="metadata page-metadata" data-bi-name="page info" lang="en-us" dir="ltr"><li>Article</li><li class="visibility-hidden-visual-diff"><time class="is-invisible" data-article-date aria-label="Article review date" datetime="2022-12-04T01:04:00Z" data-article-date-source="calculated">12/04/2022</time> </li><li class="contributors-holder display-none-print"> <button aria-label="View all contributors" class="contributors-button link-button" data-bi-name="contributors" title="View all contributors">26 contributors</button> </li></ul> </div> <div id="user-feedback" class="margin-block-xxs display-none-print" data-hide-on-archived> <button id="user-feedback-button" data-test-id="conceptual-feedback-button" class="button button-sm button-clear button-primary" type="button" data-bi-name="user-feedback-button" data-user-feedback-button > <span class="icon" aria-hidden="true"> <span class="docon docon-like"></span> </span> <span>Feedback</span> </button> </div></div><nav id="center-doc-outline" class="doc-outline is-hidden-desktop display-none-print margin-bottom-sm" data-bi-name="intopic toc" aria-label="In this article"> <h2 id="ms--in-this-article" class="title is-6 margin-block-xs">In this article</h2> </nav><!-- <content> --><p>A date and time format string defines the text representation of a <a href="/en-us/dotnet/api/system.datetime" class="no-loc" data-linktype="absolute-path">DateTime</a> or <a href="/en-us/dotnet/api/system.datetimeoffset" class="no-loc" data-linktype="absolute-path">DateTimeOffset</a> value that results from a formatting operation. It can also define the representation of a date and time value that is required in a parsing operation in order to successfully convert the string to a date and time. A custom format string consists of one or more custom date and time format specifiers. Any string that is not a <a href="standard-date-and-time-format-strings" data-linktype="relative-path">standard date and time format string</a> is interpreted as a custom date and time format string.</p> <div class="TIP"> <p>Tip</p> <p>You can download the <strong>Formatting Utility</strong>, a .NET Core Windows Forms application that lets you apply format strings to either numeric or date and time values and displays the result string. Source code is available for <a href="/en-us/samples/dotnet/samples/windowsforms-formatting-utility-cs" data-linktype="absolute-path">C#</a> and <a href="/en-us/samples/dotnet/samples/windowsforms-formatting-utility-vb" data-linktype="absolute-path">Visual Basic</a>.</p> </div> <p>Custom date and time format strings can be used with both <a href="/en-us/dotnet/api/system.datetime" class="no-loc" data-linktype="absolute-path">DateTime</a> and <a href="/en-us/dotnet/api/system.datetimeoffset" class="no-loc" data-linktype="absolute-path">DateTimeOffset</a> values.</p> <div class="NOTE"> <p>Note</p> <p>Some of the C# examples in this article run in the <a href="https://dotnet.microsoft.com/platform/try-dotnet" data-linktype="external">Try.NET</a> inline code runner and playground. Select the <strong>Run</strong> button to run an example in an interactive window. Once you execute the code, you can modify it and run the modified code by selecting <strong>Run</strong> again. The modified code either runs in the interactive window or, if compilation fails, the interactive window displays all C# compiler error messages.</p> <p>The <a href="/en-us/dotnet/api/system.timezoneinfo.local#system-timezoneinfo-local" data-linktype="absolute-path">local time zone</a> of the <a href="https://dotnet.microsoft.com/platform/try-dotnet" data-linktype="external">Try.NET</a> inline code runner and playground is Coordinated Universal Time, or UTC. This may affect the behavior and the output of examples that illustrate the <a href="/en-us/dotnet/api/system.datetime" class="no-loc" data-linktype="absolute-path">DateTime</a>, <a href="/en-us/dotnet/api/system.datetimeoffset" class="no-loc" data-linktype="absolute-path">DateTimeOffset</a>, and <a href="/en-us/dotnet/api/system.timezoneinfo" class="no-loc" data-linktype="absolute-path">TimeZoneInfo</a> types and their members.</p> </div> <p>In formatting operations, custom date and time format strings can be used either with the <code>ToString</code> method of a date and time instance or with a method that supports composite formatting. The following example illustrates both uses.</p> <pre><code class="lang-csharp" data-interactive="csharp" name="Formatting.DateAndTime.Custom#17">DateTime thisDate1 = new DateTime(2011, 6, 10); Console.WriteLine("Today is " + thisDate1.ToString("MMMM dd, yyyy") + "."); DateTimeOffset thisDate2 = new DateTimeOffset(2011, 6, 10, 15, 24, 16, TimeSpan.Zero); Console.WriteLine("The current date and time: {0:MM/dd/yy H:mm:ss zzz}", thisDate2); // The example displays the following output: // Today is June 10, 2011. // The current date and time: 06/10/11 15:24:16 +00:00 </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#17">Dim thisDate1 As Date = #6/10/2011# Console.WriteLine("Today is " + thisDate1.ToString("MMMM dd, yyyy") + ".") Dim thisDate2 As New DateTimeOffset(2011, 6, 10, 15, 24, 16, TimeSpan.Zero) Console.WriteLine("The current date and time: {0:MM/dd/yy H:mm:ss zzz}", thisDate2) ' The example displays the following output: ' Today is June 10, 2011. ' The current date and time: 06/10/11 15:24:16 +00:00 </code></pre> <p>In parsing operations, custom date and time format strings can be used with the <a href="/en-us/dotnet/api/system.datetime.parseexact" class="no-loc" data-linktype="absolute-path">DateTime.ParseExact</a>, <a href="/en-us/dotnet/api/system.datetime.tryparseexact" class="no-loc" data-linktype="absolute-path">DateTime.TryParseExact</a>, <a href="/en-us/dotnet/api/system.datetimeoffset.parseexact" class="no-loc" data-linktype="absolute-path">DateTimeOffset.ParseExact</a>, and <a href="/en-us/dotnet/api/system.datetimeoffset.tryparseexact" class="no-loc" data-linktype="absolute-path">DateTimeOffset.TryParseExact</a> methods. These methods require that an input string conforms exactly to a particular pattern for the parse operation to succeed. The following example illustrates a call to the <a href="/en-us/dotnet/api/system.datetimeoffset.parseexact#system-datetimeoffset-parseexact(system-string-system-string-system-iformatprovider)" class="no-loc" data-linktype="absolute-path">DateTimeOffset.ParseExact(String, String, IFormatProvider)</a> method to parse a date that must include a day, a month, and a two-digit year.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#18">using System; using System.Globalization; public class Example1 { public static void Main() { string[] dateValues = { "30-12-2011", "12-30-2011", "30-12-11", "12-30-11" }; string pattern = "MM-dd-yy"; DateTime parsedDate; foreach (var dateValue in dateValues) { if (DateTime.TryParseExact(dateValue, pattern, null, DateTimeStyles.None, out parsedDate)) Console.WriteLine("Converted '{0}' to {1:d}.", dateValue, parsedDate); else Console.WriteLine("Unable to convert '{0}' to a date and time.", dateValue); } } } // The example displays the following output: // Unable to convert '30-12-2011' to a date and time. // Unable to convert '12-30-2011' to a date and time. // Unable to convert '30-12-11' to a date and time. // Converted '12-30-11' to 12/30/2011. </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#18">Imports System.Globalization Module Example Public Sub Main() Dim dateValues() As String = {"30-12-2011", "12-30-2011", "30-12-11", "12-30-11"} Dim pattern As String = "MM-dd-yy" Dim parsedDate As Date For Each dateValue As String In dateValues If DateTime.TryParseExact(dateValue, pattern, Nothing, DateTimeStyles.None, parsedDate) Then Console.WriteLine("Converted '{0}' to {1:d}.", dateValue, parsedDate) Else Console.WriteLine("Unable to convert '{0}' to a date and time.", dateValue) End If Next End Sub End Module ' The example displays the following output: ' Unable to convert '30-12-2011' to a date and time. ' Unable to convert '12-30-2011' to a date and time. ' Unable to convert '30-12-11' to a date and time. ' Converted '12-30-11' to 12/30/2011. </code></pre> <p><a name="table"></a> The following table describes the custom date and time format specifiers and displays a result string produced by each format specifier. By default, result strings reflect the formatting conventions of the en-US culture. If a particular format specifier produces a localized result string, the example also notes the culture to which the result string applies. For more information about using custom date and time format strings, see the <a href="#notes" data-linktype="self-bookmark">Notes</a> section.</p> <table> <thead> <tr> <th>Format specifier</th> <th>Description</th> <th>Examples</th> </tr> </thead> <tbody> <tr> <td>"d"</td> <td>The day of the month, from 1 to 31.<br><br> More information: <a href="#dSpecifier" data-linktype="self-bookmark">The "d" Custom Format Specifier</a>.</td> <td>2009-06-01T13:45:30 -&gt; 1<br><br> 2009-06-15T13:45:30 -&gt; 15</td> </tr> <tr> <td>"dd"</td> <td>The day of the month, from 01 to 31.<br><br> More information: <a href="#ddSpecifier" data-linktype="self-bookmark">The "dd" Custom Format Specifier</a>.</td> <td>2009-06-01T13:45:30 -&gt; 01<br><br> 2009-06-15T13:45:30 -&gt; 15</td> </tr> <tr> <td>"ddd"</td> <td>The abbreviated name of the day of the week.<br><br> More information: <a href="#dddSpecifier" data-linktype="self-bookmark">The "ddd" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30 -&gt; Mon (en-US)<br><br> 2009-06-15T13:45:30 -&gt; Пн (ru-RU)<br><br> 2009-06-15T13:45:30 -&gt; lun. (fr-FR)</td> </tr> <tr> <td>"dddd"</td> <td>The full name of the day of the week.<br><br> More information: <a href="#ddddSpecifier" data-linktype="self-bookmark">The "dddd" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30 -&gt; Monday (en-US)<br><br> 2009-06-15T13:45:30 -&gt; понедельник (ru-RU)<br><br> 2009-06-15T13:45:30 -&gt; lundi (fr-FR)</td> </tr> <tr> <td>"f"</td> <td>The tenths of a second in a date and time value.<br><br> More information: <a href="#fSpecifier" data-linktype="self-bookmark">The "f" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30.6170000 -&gt; 6<br><br> 2009-06-15T13:45:30.05 -&gt; 0</td> </tr> <tr> <td>"ff"</td> <td>The hundredths of a second in a date and time value.<br><br> More information: <a href="#ffSpecifier" data-linktype="self-bookmark">The "ff" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30.6170000 -&gt; 61<br><br> 2009-06-15T13:45:30.0050000 -&gt; 00</td> </tr> <tr> <td>"fff"</td> <td>The milliseconds in a date and time value.<br><br> More information: <a href="#fffSpecifier" data-linktype="self-bookmark">The "fff" Custom Format Specifier</a>.</td> <td>6/15/2009 13:45:30.617 -&gt; 617<br><br> 6/15/2009 13:45:30.0005 -&gt; 000</td> </tr> <tr> <td>"ffff"</td> <td>The ten thousandths of a second in a date and time value.<br><br> More information: <a href="#ffffSpecifier" data-linktype="self-bookmark">The "ffff" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30.6175000 -&gt; 6175<br><br> 2009-06-15T13:45:30.0000500 -&gt; 0000</td> </tr> <tr> <td>"fffff"</td> <td>The hundred thousandths of a second in a date and time value.<br><br> More information: <a href="#fffffSpecifier" data-linktype="self-bookmark">The "fffff" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30.6175400 -&gt; 61754<br><br> 6/15/2009 13:45:30.000005 -&gt; 00000</td> </tr> <tr> <td>"ffffff"</td> <td>The millionths of a second in a date and time value.<br><br> More information: <a href="#ffffffSpecifier" data-linktype="self-bookmark">The "ffffff" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30.6175420 -&gt; 617542<br><br> 2009-06-15T13:45:30.0000005 -&gt; 000000</td> </tr> <tr> <td>"fffffff"</td> <td>The ten millionths of a second in a date and time value.<br><br> More information: <a href="#fffffffSpecifier" data-linktype="self-bookmark">The "fffffff" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30.6175425 -&gt; 6175425<br><br> 2009-06-15T13:45:30.0001150 -&gt; 0001150</td> </tr> <tr> <td>"F"</td> <td>If non-zero, the tenths of a second in a date and time value.<br><br> More information: <a href="#F_Specifier" data-linktype="self-bookmark">The "F" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30.6170000 -&gt; 6<br><br> 2009-06-15T13:45:30.0500000 -&gt; (no output)</td> </tr> <tr> <td>"FF"</td> <td>If non-zero, the hundredths of a second in a date and time value.<br><br> More information: <a href="#FF_Specifier" data-linktype="self-bookmark">The "FF" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30.6170000 -&gt; 61<br><br> 2009-06-15T13:45:30.0050000 -&gt; (no output)</td> </tr> <tr> <td>"FFF"</td> <td>If non-zero, the milliseconds in a date and time value.<br><br> More information: <a href="#FFF_Specifier" data-linktype="self-bookmark">The "FFF" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30.6170000 -&gt; 617<br><br> 2009-06-15T13:45:30.0005000 -&gt; (no output)</td> </tr> <tr> <td>"FFFF"</td> <td>If non-zero, the ten thousandths of a second in a date and time value.<br><br> More information: <a href="#FFFF_Specifier" data-linktype="self-bookmark">The "FFFF" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30.5275000 -&gt; 5275<br><br> 2009-06-15T13:45:30.0000500 -&gt; (no output)</td> </tr> <tr> <td>"FFFFF"</td> <td>If non-zero, the hundred thousandths of a second in a date and time value.<br><br> More information: <a href="#FFFFF_Specifier" data-linktype="self-bookmark">The "FFFFF" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30.6175400 -&gt; 61754<br><br> 2009-06-15T13:45:30.0000050 -&gt; (no output)</td> </tr> <tr> <td>"FFFFFF"</td> <td>If non-zero, the millionths of a second in a date and time value.<br><br> More information: <a href="#FFFFFF_Specifier" data-linktype="self-bookmark">The "FFFFFF" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30.6175420 -&gt; 617542<br><br> 2009-06-15T13:45:30.0000005 -&gt; (no output)</td> </tr> <tr> <td>"FFFFFFF"</td> <td>If non-zero, the ten millionths of a second in a date and time value.<br><br> More information: <a href="#FFFFFFF_Specifier" data-linktype="self-bookmark">The "FFFFFFF" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30.6175425 -&gt; 6175425<br><br> 2009-06-15T13:45:30.0001150 -&gt; 000115</td> </tr> <tr> <td>"g", "gg"</td> <td>The period or era.<br><br> More information: <a href="#gSpecifier" data-linktype="self-bookmark">The "g" or "gg" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30.6170000 -&gt; A.D.</td> </tr> <tr> <td>"h"</td> <td>The hour, using a 12-hour clock from 1 to 12.<br><br> More information: <a href="#hSpecifier" data-linktype="self-bookmark">The "h" Custom Format Specifier</a>.</td> <td>2009-06-15T01:45:30 -&gt; 1<br><br> 2009-06-15T13:45:30 -&gt; 1</td> </tr> <tr> <td>"hh"</td> <td>The hour, using a 12-hour clock from 01 to 12.<br><br> More information: <a href="#hhSpecifier" data-linktype="self-bookmark">The "hh" Custom Format Specifier</a>.</td> <td>2009-06-15T01:45:30 -&gt; 01<br><br> 2009-06-15T13:45:30 -&gt; 01</td> </tr> <tr> <td>"H"</td> <td>The hour, using a 24-hour clock from 0 to 23.<br><br> More information: <a href="#H_Specifier" data-linktype="self-bookmark">The "H" Custom Format Specifier</a>.</td> <td>2009-06-15T01:45:30 -&gt; 1<br><br> 2009-06-15T13:45:30 -&gt; 13</td> </tr> <tr> <td>"HH"</td> <td>The hour, using a 24-hour clock from 00 to 23.<br><br> More information: <a href="#HH_Specifier" data-linktype="self-bookmark">The "HH" Custom Format Specifier</a>.</td> <td>2009-06-15T01:45:30 -&gt; 01<br><br> 2009-06-15T13:45:30 -&gt; 13</td> </tr> <tr> <td>"K"</td> <td>Time zone information.<br><br> More information: <a href="#KSpecifier" data-linktype="self-bookmark">The "K" Custom Format Specifier</a>.</td> <td>With <a href="/en-us/dotnet/api/system.datetime" class="no-loc" data-linktype="absolute-path">DateTime</a> values:<br><br> 2009-06-15T13:45:30, Kind Unspecified -&gt;<br><br> 2009-06-15T13:45:30, Kind Utc -&gt; Z<br><br> 2009-06-15T13:45:30, Kind Local -&gt; -07:00 (depends on local computer settings)<br><br> With <a href="/en-us/dotnet/api/system.datetimeoffset" class="no-loc" data-linktype="absolute-path">DateTimeOffset</a> values:<br><br> 2009-06-15T01:45:30-07:00 --&gt; -07:00<br><br> 2009-06-15T08:45:30+00:00 --&gt; +00:00</td> </tr> <tr> <td>"m"</td> <td>The minute, from 0 to 59.<br><br> More information: <a href="#mSpecifier" data-linktype="self-bookmark">The "m" Custom Format Specifier</a>.</td> <td>2009-06-15T01:09:30 -&gt; 9<br><br> 2009-06-15T13:29:30 -&gt; 29</td> </tr> <tr> <td>"mm"</td> <td>The minute, from 00 to 59.<br><br> More information: <a href="#mmSpecifier" data-linktype="self-bookmark">The "mm" Custom Format Specifier</a>.</td> <td>2009-06-15T01:09:30 -&gt; 09<br><br> 2009-06-15T01:45:30 -&gt; 45</td> </tr> <tr> <td>"M"</td> <td>The month, from 1 to 12.<br><br> More information: <a href="#M_Specifier" data-linktype="self-bookmark">The "M" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30 -&gt; 6</td> </tr> <tr> <td>"MM"</td> <td>The month, from 01 to 12.<br><br> More information: <a href="#MM_Specifier" data-linktype="self-bookmark">The "MM" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30 -&gt; 06</td> </tr> <tr> <td>"MMM"</td> <td>The abbreviated name of the month.<br><br> More information: <a href="#MMM_Specifier" data-linktype="self-bookmark">The "MMM" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30 -&gt; Jun (en-US)<br><br> 2009-06-15T13:45:30 -&gt; juin (fr-FR)<br><br> 2009-06-15T13:45:30 -&gt; Jun (zu-ZA)</td> </tr> <tr> <td>"MMMM"</td> <td>The full name of the month.<br><br> More information: <a href="#MMMM_Specifier" data-linktype="self-bookmark">The "MMMM" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30 -&gt; June (en-US)<br><br> 2009-06-15T13:45:30 -&gt; juni (da-DK)<br><br> 2009-06-15T13:45:30 -&gt; uJuni (zu-ZA)</td> </tr> <tr> <td>"s"</td> <td>The second, from 0 to 59.<br><br> More information: <a href="#sSpecifier" data-linktype="self-bookmark">The "s" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:09 -&gt; 9</td> </tr> <tr> <td>"ss"</td> <td>The second, from 00 to 59.<br><br> More information: <a href="#ssSpecifier" data-linktype="self-bookmark">The "ss" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:09 -&gt; 09</td> </tr> <tr> <td>"t"</td> <td>The first character of the AM/PM designator.<br><br> More information: <a href="#tSpecifier" data-linktype="self-bookmark">The "t" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30 -&gt; P (en-US)<br><br> 2009-06-15T13:45:30 -&gt; 午 (ja-JP)<br><br> 2009-06-15T13:45:30 -&gt; (fr-FR)</td> </tr> <tr> <td>"tt"</td> <td>The AM/PM designator.<br><br> More information: <a href="#ttSpecifier" data-linktype="self-bookmark">The "tt" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30 -&gt; PM (en-US)<br><br> 2009-06-15T13:45:30 -&gt; 午後 (ja-JP)<br><br> 2009-06-15T13:45:30 -&gt; (fr-FR)</td> </tr> <tr> <td>"y"</td> <td>The year, from 0 to 99.<br><br> More information: <a href="#ySpecifier" data-linktype="self-bookmark">The "y" Custom Format Specifier</a>.</td> <td>0001-01-01T00:00:00 -&gt; 1<br><br> 0900-01-01T00:00:00 -&gt; 0<br><br> 1900-01-01T00:00:00 -&gt; 0<br><br> 2009-06-15T13:45:30 -&gt; 9<br><br> 2019-06-15T13:45:30 -&gt; 19</td> </tr> <tr> <td>"yy"</td> <td>The year, from 00 to 99.<br><br> More information: <a href="#yySpecifier" data-linktype="self-bookmark">The "yy" Custom Format Specifier</a>.</td> <td>0001-01-01T00:00:00 -&gt; 01<br><br> 0900-01-01T00:00:00 -&gt; 00<br><br> 1900-01-01T00:00:00 -&gt; 00<br><br> 2019-06-15T13:45:30 -&gt; 19</td> </tr> <tr> <td>"yyy"</td> <td>The year, with a minimum of three digits.<br><br> More information: <a href="#yyySpecifier" data-linktype="self-bookmark">The "yyy" Custom Format Specifier</a>.</td> <td>0001-01-01T00:00:00 -&gt; 001<br><br> 0900-01-01T00:00:00 -&gt; 900<br><br> 1900-01-01T00:00:00 -&gt; 1900<br><br> 2009-06-15T13:45:30 -&gt; 2009</td> </tr> <tr> <td>"yyyy"</td> <td>The year as a four-digit number.<br><br> More information: <a href="#yyyySpecifier" data-linktype="self-bookmark">The "yyyy" Custom Format Specifier</a>.</td> <td>0001-01-01T00:00:00 -&gt; 0001<br><br> 0900-01-01T00:00:00 -&gt; 0900<br><br> 1900-01-01T00:00:00 -&gt; 1900<br><br> 2009-06-15T13:45:30 -&gt; 2009</td> </tr> <tr> <td>"yyyyy"</td> <td>The year as a five-digit number.<br><br> More information: <a href="#yyyyySpecifier" data-linktype="self-bookmark">The "yyyyy" Custom Format Specifier</a>.</td> <td>0001-01-01T00:00:00 -&gt; 00001<br><br> 2009-06-15T13:45:30 -&gt; 02009</td> </tr> <tr> <td>"z"</td> <td>Hours offset from UTC, with no leading zeros.<br><br> More information: <a href="#zSpecifier" data-linktype="self-bookmark">The "z" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30-07:00 -&gt; -7</td> </tr> <tr> <td>"zz"</td> <td>Hours offset from UTC, with a leading zero for a single-digit value.<br><br> More information: <a href="#zzSpecifier" data-linktype="self-bookmark">The "zz" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30-07:00 -&gt; -07</td> </tr> <tr> <td>"zzz"</td> <td>Hours and minutes offset from UTC.<br><br> More information: <a href="#zzzSpecifier" data-linktype="self-bookmark">The "zzz" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30-07:00 -&gt; -07:00</td> </tr> <tr> <td>":"</td> <td>The time separator.<br><br> More information: <a href="#timeSeparator" data-linktype="self-bookmark">The ":" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30 -&gt; : (en-US)<br><br> 2009-06-15T13:45:30 -&gt; . (it-IT)<br><br> 2009-06-15T13:45:30 -&gt; : (ja-JP)</td> </tr> <tr> <td>"/"</td> <td>The date separator.<br><br> More Information: <a href="#dateSeparator" data-linktype="self-bookmark">The "/" Custom Format Specifier</a>.</td> <td>2009-06-15T13:45:30 -&gt; / (en-US)<br><br> 2009-06-15T13:45:30 -&gt; - (ar-DZ)<br><br> 2009-06-15T13:45:30 -&gt; . (tr-TR)</td> </tr> <tr> <td>"<em>string</em>"<br><br> '<em>string</em>'</td> <td>Literal string delimiter.<br><br> More information: <a href="#Literals" data-linktype="self-bookmark">Character literals</a>.</td> <td>2009-06-15T13:45:30 ("arr:" h:m t) -&gt; arr: 1:45 P<br><br> 2009-06-15T13:45:30 ('arr:' h:m t) -&gt; arr: 1:45 P</td> </tr> <tr> <td>%</td> <td>Defines the following character as a custom format specifier.<br><br> More information: <a href="#UsingSingleSpecifiers" data-linktype="self-bookmark">Using Single Custom Format Specifiers</a>.</td> <td>2009-06-15T13:45:30 (%h) -&gt; 1</td> </tr> <tr> <td>\</td> <td>The escape character.<br><br> More information: <a href="#Literals" data-linktype="self-bookmark">Character literals</a> and <a href="#escape" data-linktype="self-bookmark">Using the Escape Character</a>.</td> <td>2009-06-15T13:45:30 (h \h) -&gt; 1 h</td> </tr> <tr> <td>Any other character</td> <td>The character is copied to the result string unchanged.<br><br> More information: <a href="#Literals" data-linktype="self-bookmark">Character literals</a>.</td> <td>2009-06-15T01:45:30 (arr hh:mm t) -&gt; arr 01:45 A</td> </tr> </tbody> </table> <p>The following sections provide additional information about each custom date and time format specifier. Unless otherwise noted, each specifier produces an identical string representation regardless of whether it's used with a <a href="/en-us/dotnet/api/system.datetime" class="no-loc" data-linktype="absolute-path">DateTime</a> value or a <a href="/en-us/dotnet/api/system.datetimeoffset" class="no-loc" data-linktype="absolute-path">DateTimeOffset</a> value.</p> <h2 id="day-d-format-specifier">Day "d" format specifier</h2> <h3 id="dSpecifier"> The "d" custom format specifier</h3> <p>The "d" custom format specifier represents the day of the month as a number from 1 to 31. A single-digit day is formatted without a leading zero.</p> <p>If the "d" format specifier is used without other custom format specifiers, it's interpreted as the "d" standard date and time format specifier. For more information about using a single format specifier, see <a href="#UsingSingleSpecifiers" data-linktype="self-bookmark">Using Single Custom Format Specifiers</a> later in this article.</p> <p>The following example includes the "d" custom format specifier in several format strings.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#1">DateTime date1 = new DateTime(2008, 8, 29, 19, 27, 15); Console.WriteLine(date1.ToString("d, M", CultureInfo.InvariantCulture)); // Displays 29, 8 Console.WriteLine(date1.ToString("d MMMM", CultureInfo.CreateSpecificCulture("en-US"))); // Displays 29 August Console.WriteLine(date1.ToString("d MMMM", CultureInfo.CreateSpecificCulture("es-MX"))); // Displays 29 agosto </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#1">Dim date1 As Date = #08/29/2008 7:27:15PM# Console.WriteLine(date1.ToString("d, M", _ CultureInfo.InvariantCulture)) ' Displays 29, 8 Console.WriteLine(date1.ToString("d MMMM", _ CultureInfo.CreateSpecificCulture("en-US"))) ' Displays 29 August Console.WriteLine(date1.ToString("d MMMM", _ CultureInfo.CreateSpecificCulture("es-MX"))) ' Displays 29 agosto </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="ddSpecifier"> The "dd" custom format specifier</h3> <p>The "dd" custom format string represents the day of the month as a number from 01 to 31. A single-digit day is formatted with a leading zero.</p> <p>The following example includes the "dd" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#2">DateTime date1 = new DateTime(2008, 1, 2, 6, 30, 15); Console.WriteLine(date1.ToString("dd, MM", CultureInfo.InvariantCulture)); // 02, 01 </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#2">Dim date1 As Date = #1/2/2008 6:30:15AM# Console.WriteLine(date1.ToString("dd, MM", _ CultureInfo.InvariantCulture)) ' 02, 01 </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="dddSpecifier"> The "ddd" custom format specifier</h3> <p>The "ddd" custom format specifier represents the abbreviated name of the day of the week. The localized abbreviated name of the day of the week is retrieved from the <a href="/en-us/dotnet/api/system.globalization.datetimeformatinfo.abbreviateddaynames" class="no-loc" data-linktype="absolute-path">DateTimeFormatInfo.AbbreviatedDayNames</a> property of the current or specified culture.</p> <p>The following example includes the "ddd" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#3">DateTime date1 = new DateTime(2008, 8, 29, 19, 27, 15); Console.WriteLine(date1.ToString("ddd d MMM", CultureInfo.CreateSpecificCulture("en-US"))); // Displays Fri 29 Aug Console.WriteLine(date1.ToString("ddd d MMM", CultureInfo.CreateSpecificCulture("fr-FR"))); // Displays ven. 29 août </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#3">Dim date1 As Date = #08/29/2008 7:27:15PM# Console.WriteLine(date1.ToString("ddd d MMM", _ CultureInfo.CreateSpecificCulture("en-US"))) ' Displays Fri 29 Aug Console.WriteLine(date1.ToString("ddd d MMM", _ CultureInfo.CreateSpecificCulture("fr-FR"))) ' Displays ven. 29 août </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="ddddSpecifier"> The "dddd" custom format specifier</h3> <p>The "dddd" custom format specifier (plus any number of additional "d" specifiers) represents the full name of the day of the week. The localized name of the day of the week is retrieved from the <a href="/en-us/dotnet/api/system.globalization.datetimeformatinfo.daynames" class="no-loc" data-linktype="absolute-path">DateTimeFormatInfo.DayNames</a> property of the current or specified culture.</p> <p>The following example includes the "dddd" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#4">DateTime date1 = new DateTime(2008, 8, 29, 19, 27, 15); Console.WriteLine(date1.ToString("dddd dd MMMM", CultureInfo.CreateSpecificCulture("en-US"))); // Displays Friday 29 August Console.WriteLine(date1.ToString("dddd dd MMMM", CultureInfo.CreateSpecificCulture("it-IT"))); // Displays venerdì 29 agosto </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#4">Dim date1 As Date = #08/29/2008 7:27:15PM# Console.WriteLine(date1.ToString("dddd dd MMMM", _ CultureInfo.CreateSpecificCulture("en-US"))) ' Displays Friday 29 August Console.WriteLine(date1.ToString("dddd dd MMMM", _ CultureInfo.CreateSpecificCulture("it-IT"))) ' Displays venerdì 29 agosto </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h2 id="lowercase-seconds-f-fraction-specifier">Lowercase seconds "f" fraction specifier</h2> <h3 id="fSpecifier"> The "f" custom format specifier</h3> <p>The "f" custom format specifier represents the most significant digit of the seconds fraction; that is, it represents the tenths of a second in a date and time value.</p> <p>If the "f" format specifier is used without other format specifiers, it's interpreted as the "f" standard date and time format specifier. For more information about using a single format specifier, see <a href="#UsingSingleSpecifiers" data-linktype="self-bookmark">Using Single Custom Format Specifiers</a> later in this article.</p> <p>When you use "f" format specifiers as part of a format string supplied to the <a href="/en-us/dotnet/api/system.datetime.parseexact" class="no-loc" data-linktype="absolute-path">ParseExact</a>, <a href="/en-us/dotnet/api/system.datetime.tryparseexact" class="no-loc" data-linktype="absolute-path">TryParseExact</a>, <a href="/en-us/dotnet/api/system.datetimeoffset.parseexact" class="no-loc" data-linktype="absolute-path">ParseExact</a>, or <a href="/en-us/dotnet/api/system.datetimeoffset.tryparseexact" class="no-loc" data-linktype="absolute-path">TryParseExact</a> method, the number of "f" format specifiers indicates the number of most significant digits of the seconds fraction that must be present to successfully parse the string.</p> <p>The following example includes the "f" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#5">DateTime date1 = new DateTime(2008, 8, 29, 19, 27, 15, 18); CultureInfo ci = CultureInfo.InvariantCulture; Console.WriteLine(date1.ToString("hh:mm:ss.f", ci)); // Displays 07:27:15.0 Console.WriteLine(date1.ToString("hh:mm:ss.F", ci)); // Displays 07:27:15 Console.WriteLine(date1.ToString("hh:mm:ss.ff", ci)); // Displays 07:27:15.01 Console.WriteLine(date1.ToString("hh:mm:ss.FF", ci)); // Displays 07:27:15.01 Console.WriteLine(date1.ToString("hh:mm:ss.fff", ci)); // Displays 07:27:15.018 Console.WriteLine(date1.ToString("hh:mm:ss.FFF", ci)); // Displays 07:27:15.018 </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#5">Dim date1 As New Date(2008, 8, 29, 19, 27, 15, 018) Dim ci As CultureInfo = CultureInfo.InvariantCulture Console.WriteLine(date1.ToString("hh:mm:ss.f", ci)) ' Displays 07:27:15.0 Console.WriteLine(date1.ToString("hh:mm:ss.F", ci)) ' Displays 07:27:15 Console.WriteLine(date1.ToString("hh:mm:ss.ff", ci)) ' Displays 07:27:15.01 Console.WriteLine(date1.ToString("hh:mm:ss.FF", ci)) ' Displays 07:27:15.01 Console.WriteLine(date1.ToString("hh:mm:ss.fff", ci)) ' Displays 07:27:15.018 Console.WriteLine(date1.ToString("hh:mm:ss.FFF", ci)) ' Displays 07:27:15.018 </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="ffSpecifier"> The "ff" custom format specifier</h3> <p>The "ff" custom format specifier represents the two most significant digits of the seconds fraction; that is, it represents the hundredths of a second in a date and time value.</p> <p>following example includes the "ff" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#5">DateTime date1 = new DateTime(2008, 8, 29, 19, 27, 15, 18); CultureInfo ci = CultureInfo.InvariantCulture; Console.WriteLine(date1.ToString("hh:mm:ss.f", ci)); // Displays 07:27:15.0 Console.WriteLine(date1.ToString("hh:mm:ss.F", ci)); // Displays 07:27:15 Console.WriteLine(date1.ToString("hh:mm:ss.ff", ci)); // Displays 07:27:15.01 Console.WriteLine(date1.ToString("hh:mm:ss.FF", ci)); // Displays 07:27:15.01 Console.WriteLine(date1.ToString("hh:mm:ss.fff", ci)); // Displays 07:27:15.018 Console.WriteLine(date1.ToString("hh:mm:ss.FFF", ci)); // Displays 07:27:15.018 </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#5">Dim date1 As New Date(2008, 8, 29, 19, 27, 15, 018) Dim ci As CultureInfo = CultureInfo.InvariantCulture Console.WriteLine(date1.ToString("hh:mm:ss.f", ci)) ' Displays 07:27:15.0 Console.WriteLine(date1.ToString("hh:mm:ss.F", ci)) ' Displays 07:27:15 Console.WriteLine(date1.ToString("hh:mm:ss.ff", ci)) ' Displays 07:27:15.01 Console.WriteLine(date1.ToString("hh:mm:ss.FF", ci)) ' Displays 07:27:15.01 Console.WriteLine(date1.ToString("hh:mm:ss.fff", ci)) ' Displays 07:27:15.018 Console.WriteLine(date1.ToString("hh:mm:ss.FFF", ci)) ' Displays 07:27:15.018 </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="fffSpecifier"> The "fff" custom format specifier</h3> <p>The "fff" custom format specifier represents the three most significant digits of the seconds fraction; that is, it represents the milliseconds in a date and time value.</p> <p>The following example includes the "fff" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#5">DateTime date1 = new DateTime(2008, 8, 29, 19, 27, 15, 18); CultureInfo ci = CultureInfo.InvariantCulture; Console.WriteLine(date1.ToString("hh:mm:ss.f", ci)); // Displays 07:27:15.0 Console.WriteLine(date1.ToString("hh:mm:ss.F", ci)); // Displays 07:27:15 Console.WriteLine(date1.ToString("hh:mm:ss.ff", ci)); // Displays 07:27:15.01 Console.WriteLine(date1.ToString("hh:mm:ss.FF", ci)); // Displays 07:27:15.01 Console.WriteLine(date1.ToString("hh:mm:ss.fff", ci)); // Displays 07:27:15.018 Console.WriteLine(date1.ToString("hh:mm:ss.FFF", ci)); // Displays 07:27:15.018 </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#5">Dim date1 As New Date(2008, 8, 29, 19, 27, 15, 018) Dim ci As CultureInfo = CultureInfo.InvariantCulture Console.WriteLine(date1.ToString("hh:mm:ss.f", ci)) ' Displays 07:27:15.0 Console.WriteLine(date1.ToString("hh:mm:ss.F", ci)) ' Displays 07:27:15 Console.WriteLine(date1.ToString("hh:mm:ss.ff", ci)) ' Displays 07:27:15.01 Console.WriteLine(date1.ToString("hh:mm:ss.FF", ci)) ' Displays 07:27:15.01 Console.WriteLine(date1.ToString("hh:mm:ss.fff", ci)) ' Displays 07:27:15.018 Console.WriteLine(date1.ToString("hh:mm:ss.FFF", ci)) ' Displays 07:27:15.018 </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="ffffSpecifier"> The "ffff" custom format specifier</h3> <p>The "ffff" custom format specifier represents the four most significant digits of the seconds fraction; that is, it represents the ten thousandths of a second in a date and time value.</p> <p>Although it's possible to display the ten thousandths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On the Windows NT version 3.5 (and later) and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.</p> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="fffffSpecifier"> The "fffff" custom format specifier</h3> <p>The "fffff" custom format specifier represents the five most significant digits of the seconds fraction; that is, it represents the hundred thousandths of a second in a date and time value.</p> <p>Although it's possible to display the hundred thousandths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On the Windows NT 3.5 (and later) and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.</p> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="ffffffSpecifier"> The "ffffff" custom format specifier</h3> <p>The "ffffff" custom format specifier represents the six most significant digits of the seconds fraction; that is, it represents the millionths of a second in a date and time value.</p> <p>Although it's possible to display the millionths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On the Windows NT 3.5 (and later) and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.</p> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="fffffffSpecifier"> The "fffffff" custom format specifier</h3> <p>The "fffffff" custom format specifier represents the seven most significant digits of the seconds fraction; that is, it represents the ten millionths of a second in a date and time value.</p> <p>Although it's possible to display the ten millionths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On the Windows NT 3.5 (and later) and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.</p> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h2 id="uppercase-seconds-f-fraction-specifier">Uppercase seconds "F" fraction specifier</h2> <h3 id="F_Specifier"> The "F" custom format specifier</h3> <p>The "F" custom format specifier represents the most significant digit of the seconds fraction; that is, it represents the tenths of a second in a date and time value. Nothing is displayed if the digit is zero, and the decimal point that follows the number of seconds is also not displayed.</p> <p>If the "F" format specifier is used without other format specifiers, it's interpreted as the "F" standard date and time format specifier. For more information about using a single format specifier, see <a href="#UsingSingleSpecifiers" data-linktype="self-bookmark">Using Single Custom Format Specifiers</a> later in this article.</p> <p>The number of "F" format specifiers used with the <a href="/en-us/dotnet/api/system.datetime.parseexact" class="no-loc" data-linktype="absolute-path">ParseExact</a>, <a href="/en-us/dotnet/api/system.datetime.tryparseexact" class="no-loc" data-linktype="absolute-path">TryParseExact</a>, <a href="/en-us/dotnet/api/system.datetimeoffset.parseexact" class="no-loc" data-linktype="absolute-path">ParseExact</a>, or <a href="/en-us/dotnet/api/system.datetimeoffset.tryparseexact" class="no-loc" data-linktype="absolute-path">TryParseExact</a> method indicates the maximum number of most significant digits of the seconds fraction that can be present to successfully parse the string.</p> <p>The following example includes the "F" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#5">DateTime date1 = new DateTime(2008, 8, 29, 19, 27, 15, 18); CultureInfo ci = CultureInfo.InvariantCulture; Console.WriteLine(date1.ToString("hh:mm:ss.f", ci)); // Displays 07:27:15.0 Console.WriteLine(date1.ToString("hh:mm:ss.F", ci)); // Displays 07:27:15 Console.WriteLine(date1.ToString("hh:mm:ss.ff", ci)); // Displays 07:27:15.01 Console.WriteLine(date1.ToString("hh:mm:ss.FF", ci)); // Displays 07:27:15.01 Console.WriteLine(date1.ToString("hh:mm:ss.fff", ci)); // Displays 07:27:15.018 Console.WriteLine(date1.ToString("hh:mm:ss.FFF", ci)); // Displays 07:27:15.018 </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#5">Dim date1 As New Date(2008, 8, 29, 19, 27, 15, 018) Dim ci As CultureInfo = CultureInfo.InvariantCulture Console.WriteLine(date1.ToString("hh:mm:ss.f", ci)) ' Displays 07:27:15.0 Console.WriteLine(date1.ToString("hh:mm:ss.F", ci)) ' Displays 07:27:15 Console.WriteLine(date1.ToString("hh:mm:ss.ff", ci)) ' Displays 07:27:15.01 Console.WriteLine(date1.ToString("hh:mm:ss.FF", ci)) ' Displays 07:27:15.01 Console.WriteLine(date1.ToString("hh:mm:ss.fff", ci)) ' Displays 07:27:15.018 Console.WriteLine(date1.ToString("hh:mm:ss.FFF", ci)) ' Displays 07:27:15.018 </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="FF_Specifier"> The "FF" custom format specifier</h3> <p>The "FF" custom format specifier represents the two most significant digits of the seconds fraction; that is, it represents the hundredths of a second in a date and time value. Trailing zeros aren't displayed. Nothing is displayed if the two significant digits are zero, and in that case the decimal point that follows the number of seconds is also not displayed.</p> <p>The following example includes the "FF" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#5">DateTime date1 = new DateTime(2008, 8, 29, 19, 27, 15, 18); CultureInfo ci = CultureInfo.InvariantCulture; Console.WriteLine(date1.ToString("hh:mm:ss.f", ci)); // Displays 07:27:15.0 Console.WriteLine(date1.ToString("hh:mm:ss.F", ci)); // Displays 07:27:15 Console.WriteLine(date1.ToString("hh:mm:ss.ff", ci)); // Displays 07:27:15.01 Console.WriteLine(date1.ToString("hh:mm:ss.FF", ci)); // Displays 07:27:15.01 Console.WriteLine(date1.ToString("hh:mm:ss.fff", ci)); // Displays 07:27:15.018 Console.WriteLine(date1.ToString("hh:mm:ss.FFF", ci)); // Displays 07:27:15.018 </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#5">Dim date1 As New Date(2008, 8, 29, 19, 27, 15, 018) Dim ci As CultureInfo = CultureInfo.InvariantCulture Console.WriteLine(date1.ToString("hh:mm:ss.f", ci)) ' Displays 07:27:15.0 Console.WriteLine(date1.ToString("hh:mm:ss.F", ci)) ' Displays 07:27:15 Console.WriteLine(date1.ToString("hh:mm:ss.ff", ci)) ' Displays 07:27:15.01 Console.WriteLine(date1.ToString("hh:mm:ss.FF", ci)) ' Displays 07:27:15.01 Console.WriteLine(date1.ToString("hh:mm:ss.fff", ci)) ' Displays 07:27:15.018 Console.WriteLine(date1.ToString("hh:mm:ss.FFF", ci)) ' Displays 07:27:15.018 </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="FFF_Specifier"> The "FFF" custom format specifier</h3> <p>The "FFF" custom format specifier represents the three most significant digits of the seconds fraction; that is, it represents the milliseconds in a date and time value. Trailing zeros aren't displayed. Nothing is displayed if the three significant digits are zero, and in that case the decimal point that follows the number of seconds is also not displayed.</p> <p>The following example includes the "FFF" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#5">DateTime date1 = new DateTime(2008, 8, 29, 19, 27, 15, 18); CultureInfo ci = CultureInfo.InvariantCulture; Console.WriteLine(date1.ToString("hh:mm:ss.f", ci)); // Displays 07:27:15.0 Console.WriteLine(date1.ToString("hh:mm:ss.F", ci)); // Displays 07:27:15 Console.WriteLine(date1.ToString("hh:mm:ss.ff", ci)); // Displays 07:27:15.01 Console.WriteLine(date1.ToString("hh:mm:ss.FF", ci)); // Displays 07:27:15.01 Console.WriteLine(date1.ToString("hh:mm:ss.fff", ci)); // Displays 07:27:15.018 Console.WriteLine(date1.ToString("hh:mm:ss.FFF", ci)); // Displays 07:27:15.018 </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#5">Dim date1 As New Date(2008, 8, 29, 19, 27, 15, 018) Dim ci As CultureInfo = CultureInfo.InvariantCulture Console.WriteLine(date1.ToString("hh:mm:ss.f", ci)) ' Displays 07:27:15.0 Console.WriteLine(date1.ToString("hh:mm:ss.F", ci)) ' Displays 07:27:15 Console.WriteLine(date1.ToString("hh:mm:ss.ff", ci)) ' Displays 07:27:15.01 Console.WriteLine(date1.ToString("hh:mm:ss.FF", ci)) ' Displays 07:27:15.01 Console.WriteLine(date1.ToString("hh:mm:ss.fff", ci)) ' Displays 07:27:15.018 Console.WriteLine(date1.ToString("hh:mm:ss.FFF", ci)) ' Displays 07:27:15.018 </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="FFFF_Specifier"> The "FFFF" custom format specifier</h3> <p>The "FFFF" custom format specifier represents the four most significant digits of the seconds fraction; that is, it represents the ten thousandths of a second in a date and time value. Trailing zeros aren't displayed. Nothing is displayed if the four significant digits are zero, and in that case the decimal point that follows the number of seconds is also not displayed.</p> <p>Although it's possible to display the ten thousandths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On the Windows NT 3.5 (and later) and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.</p> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="FFFFF_Specifier"> The "FFFFF" custom format specifier</h3> <p>The "FFFFF" custom format specifier represents the five most significant digits of the seconds fraction; that is, it represents the hundred thousandths of a second in a date and time value. Trailing zeros aren't displayed. Nothing is displayed if the five significant digits are zero, and in that case the decimal point that follows the number of seconds is also not displayed.</p> <p>Although it's possible to display the hundred thousandths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On the Windows NT 3.5 (and later) and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.</p> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="FFFFFF_Specifier"> The "FFFFFF" custom format specifier</h3> <p>The "FFFFFF" custom format specifier represents the six most significant digits of the seconds fraction; that is, it represents the millionths of a second in a date and time value. Trailing zeros aren't displayed. Nothing is displayed if the six significant digits are zero, and in that case the decimal point that follows the number of seconds is also not displayed.</p> <p>Although it's possible to display the millionths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On the Windows NT 3.5 (and later) and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.</p> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="FFFFFFF_Specifier"> The "FFFFFFF" custom format specifier</h3> <p>The "FFFFFFF" custom format specifier represents the seven most significant digits of the seconds fraction; that is, it represents the ten millionths of a second in a date and time value. Trailing zeros aren't displayed. Nothing is displayed if the seven significant digits are zero, and in that case the decimal point that follows the number of seconds is also not displayed.</p> <p>Although it's possible to display the ten millionths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On the Windows NT 3.5 (and later) and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.</p> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h2 id="era-g-format-specifier">Era "g" format specifier</h2> <h3 id="gSpecifier"> The "g" or "gg" custom format specifier</h3> <p>The "g" or "gg" custom format specifiers (plus any number of additional "g" specifiers) represents the period or era, such as A.D. The formatting operation ignores this specifier if the date to be formatted doesn't have an associated period or era string.</p> <p>If the "g" format specifier is used without other custom format specifiers, it's interpreted as the "g" standard date and time format specifier. For more information about using a single format specifier, see <a href="#UsingSingleSpecifiers" data-linktype="self-bookmark">Using Single Custom Format Specifiers</a> later in this article.</p> <p>The following example includes the "g" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#6">DateTime date1 = new DateTime(70, 08, 04); Console.WriteLine(date1.ToString("MM/dd/yyyy g", CultureInfo.InvariantCulture)); // Displays 08/04/0070 A.D. Console.WriteLine(date1.ToString("MM/dd/yyyy g", CultureInfo.CreateSpecificCulture("fr-FR"))); // Displays 08/04/0070 ap. J.-C. </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#6">Dim date1 As Date = #08/04/0070# Console.WriteLine(date1.ToString("MM/dd/yyyy g", _ CultureInfo.InvariantCulture)) ' Displays 08/04/0070 A.D. Console.WriteLine(date1.ToString("MM/dd/yyyy g", _ CultureInfo.CreateSpecificCulture("fr-FR"))) ' Displays 08/04/0070 ap. J.-C. </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h2 id="lowercase-hour-h-format-specifier">Lowercase hour "h" format specifier</h2> <h3 id="hSpecifier"> The "h" custom format specifier</h3> <p>The "h" custom format specifier represents the hour as a number from 1 to 12; that is, the hour is represented by a 12-hour clock that counts the whole hours since midnight or noon. A particular hour after midnight is indistinguishable from the same hour after noon. The hour is not rounded, and a single-digit hour is formatted without a leading zero. For example, given a time of 5:43 in the morning or afternoon, this custom format specifier displays "5".</p> <p>If the "h" format specifier is used without other custom format specifiers, it's interpreted as a standard date and time format specifier and throws a <a href="/en-us/dotnet/api/system.formatexception" class="no-loc" data-linktype="absolute-path">FormatException</a>. For more information about using a single format specifier, see <a href="#UsingSingleSpecifiers" data-linktype="self-bookmark">Using Single Custom Format Specifiers</a> later in this article.</p> <p>The following example includes the "h" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#7">DateTime date1; date1 = new DateTime(2008, 1, 1, 18, 9, 1); Console.WriteLine(date1.ToString("h:m:s.F t", CultureInfo.InvariantCulture)); // Displays 6:9:1 P Console.WriteLine(date1.ToString("h:m:s.F t", CultureInfo.CreateSpecificCulture("el-GR"))); // Displays 6:9:1 µ date1 = new DateTime(2008, 1, 1, 18, 9, 1, 500); Console.WriteLine(date1.ToString("h:m:s.F t", CultureInfo.InvariantCulture)); // Displays 6:9:1.5 P Console.WriteLine(date1.ToString("h:m:s.F t", CultureInfo.CreateSpecificCulture("el-GR"))); // Displays 6:9:1.5 µ </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#7">Dim date1 As Date date1 = #6:09:01PM# Console.WriteLine(date1.ToString("h:m:s.F t", _ CultureInfo.InvariantCulture)) ' Displays 6:9:1 P Console.WriteLine(date1.ToString("h:m:s.F t", _ CultureInfo.CreateSpecificCulture("el-GR"))) ' Displays 6:9:1 µ date1 = New Date(2008, 1, 1, 18, 9, 1, 500) Console.WriteLine(date1.ToString("h:m:s.F t", _ CultureInfo.InvariantCulture)) ' Displays 6:9:1.5 P Console.WriteLine(date1.ToString("h:m:s.F t", _ CultureInfo.CreateSpecificCulture("el-GR"))) ' Displays 6:9:1.5 µ </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="hhSpecifier"> The "hh" custom format specifier</h3> <p>The "hh" custom format specifier (plus any number of additional "h" specifiers) represents the hour as a number from 01 to 12; that is, the hour is represented by a 12-hour clock that counts the whole hours since midnight or noon. A particular hour after midnight is indistinguishable from the same hour after noon. The hour is not rounded, and a single-digit hour is formatted with a leading zero. For example, given a time of 5:43 in the morning or afternoon, this format specifier displays "05".</p> <p>The following example includes the "hh" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#8">DateTime date1; date1 = new DateTime(2008, 1, 1, 18, 9, 1); Console.WriteLine(date1.ToString("hh:mm:ss tt", CultureInfo.InvariantCulture)); // Displays 06:09:01 PM Console.WriteLine(date1.ToString("hh:mm:ss tt", CultureInfo.CreateSpecificCulture("hu-HU"))); // Displays 06:09:01 du. date1 = new DateTime(2008, 1, 1, 18, 9, 1, 500); Console.WriteLine(date1.ToString("hh:mm:ss.ff tt", CultureInfo.InvariantCulture)); // Displays 06:09:01.50 PM Console.WriteLine(date1.ToString("hh:mm:ss.ff tt", CultureInfo.CreateSpecificCulture("hu-HU"))); // Displays 06:09:01.50 du. </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#8">Dim date1 As Date date1 = #6:09:01PM# Console.WriteLine(date1.ToString("hh:mm:ss tt", _ CultureInfo.InvariantCulture)) ' Displays 06:09:01 PM Console.WriteLine(date1.ToString("hh:mm:ss tt", _ CultureInfo.CreateSpecificCulture("hu-HU"))) ' Displays 06:09:01 du. date1 = New Date(2008, 1, 1, 18, 9, 1, 500) Console.WriteLine(date1.ToString("hh:mm:ss.ff tt", _ CultureInfo.InvariantCulture)) ' Displays 06:09:01.50 PM Console.WriteLine(date1.ToString("hh:mm:ss.ff tt", _ CultureInfo.CreateSpecificCulture("hu-HU"))) ' Displays 06:09:01.50 du. </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h2 id="uppercase-hour-h-format-specifier">Uppercase hour "H" format specifier</h2> <h3 id="H_Specifier"> The "H" custom format specifier</h3> <p>The "H" custom format specifier represents the hour as a number from 0 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 without a leading zero.</p> <p>If the "H" format specifier is used without other custom format specifiers, it's interpreted as a standard date and time format specifier and throws a <a href="/en-us/dotnet/api/system.formatexception" class="no-loc" data-linktype="absolute-path">FormatException</a>. For more information about using a single format specifier, see <a href="#UsingSingleSpecifiers" data-linktype="self-bookmark">Using Single Custom Format Specifiers</a> later in this article.</p> <p>The following example includes the "H" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#9">DateTime date1 = new DateTime(2008, 1, 1, 6, 9, 1); Console.WriteLine(date1.ToString("H:mm:ss", CultureInfo.InvariantCulture)); // Displays 6:09:01 </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#9">Dim date1 As Date = #6:09:01AM# Console.WriteLine(date1.ToString("H:mm:ss", _ CultureInfo.InvariantCulture)) ' Displays 6:09:01 </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="HH_Specifier"> The "HH" custom format specifier</h3> <p>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.</p> <p>The following example includes the "HH" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#10">DateTime date1 = new DateTime(2008, 1, 1, 6, 9, 1); Console.WriteLine(date1.ToString("HH:mm:ss", CultureInfo.InvariantCulture)); // Displays 06:09:01 </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#10">Dim date1 As Date = #6:09:01AM# Console.WriteLine(date1.ToString("HH:mm:ss", _ CultureInfo.InvariantCulture)) ' Displays 06:09:01 </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h2 id="time-zone-k-format-specifier">Time zone "K" format specifier</h2> <h3 id="KSpecifier"> The "K" custom format specifier</h3> <p>The "K" custom format specifier represents the time zone information of a date and time value. When this format specifier is used with <a href="/en-us/dotnet/api/system.datetime" class="no-loc" data-linktype="absolute-path">DateTime</a> values, the result string is defined by the value of the <a href="/en-us/dotnet/api/system.datetime.kind" class="no-loc" data-linktype="absolute-path">DateTime.Kind</a> property:</p> <ul> <li><p>For the local time zone (a <a href="/en-us/dotnet/api/system.datetime.kind" class="no-loc" data-linktype="absolute-path">DateTime.Kind</a> property value of <a href="/en-us/dotnet/api/system.datetimekind#system-datetimekind-local" class="no-loc" data-linktype="absolute-path">DateTimeKind.Local</a>), this specifier produces a result string containing the local offset from Coordinated Universal Time (UTC); for example, "-07:00".</p> </li> <li><p>For a UTC time (a <a href="/en-us/dotnet/api/system.datetime.kind" class="no-loc" data-linktype="absolute-path">DateTime.Kind</a> property value of <a href="/en-us/dotnet/api/system.datetimekind#system-datetimekind-utc" class="no-loc" data-linktype="absolute-path">DateTimeKind.Utc</a>), the result string includes a "Z" character to represent a UTC date.</p> </li> <li><p>For a time from an unspecified time zone (a time whose <a href="/en-us/dotnet/api/system.datetime.kind" class="no-loc" data-linktype="absolute-path">DateTime.Kind</a> property equals <a href="/en-us/dotnet/api/system.datetimekind#system-datetimekind-unspecified" class="no-loc" data-linktype="absolute-path">DateTimeKind.Unspecified</a>), the result is equivalent to <a href="/en-us/dotnet/api/system.string.empty#system-string-empty" class="no-loc" data-linktype="absolute-path">String.Empty</a>.</p> </li> </ul> <p>For <a href="/en-us/dotnet/api/system.datetimeoffset" class="no-loc" data-linktype="absolute-path">DateTimeOffset</a> values, the "K" format specifier is equivalent to the "zzz" format specifier, and produces a result string containing the <a href="/en-us/dotnet/api/system.datetimeoffset" class="no-loc" data-linktype="absolute-path">DateTimeOffset</a> value's offset from UTC.</p> <p>If the "K" format specifier is used without other custom format specifiers, it's interpreted as a standard date and time format specifier and throws a <a href="/en-us/dotnet/api/system.formatexception" class="no-loc" data-linktype="absolute-path">FormatException</a>. For more information about using a single format specifier, see <a href="#UsingSingleSpecifiers" data-linktype="self-bookmark">Using Single Custom Format Specifiers</a> later in this article.</p> <p>The following example displays the string that results from using the "K" custom format specifier with various <a href="/en-us/dotnet/api/system.datetime" class="no-loc" data-linktype="absolute-path">DateTime</a> and <a href="/en-us/dotnet/api/system.datetimeoffset" class="no-loc" data-linktype="absolute-path">DateTimeOffset</a> values on a system in the U.S. Pacific Time zone.</p> <pre><code class="lang-csharp" data-interactive="csharp" name="Formatting.DateAndTime.Custom#12">Console.WriteLine(DateTime.Now.ToString("%K")); // Displays -07:00 Console.WriteLine(DateTime.UtcNow.ToString("%K")); // Displays Z Console.WriteLine("'{0}'", DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Unspecified).ToString("%K")); // Displays '' Console.WriteLine(DateTimeOffset.Now.ToString("%K")); // Displays -07:00 Console.WriteLine(DateTimeOffset.UtcNow.ToString("%K")); // Displays +00:00 Console.WriteLine(new DateTimeOffset(2008, 5, 1, 6, 30, 0, new TimeSpan(5, 0, 0)).ToString("%K")); // Displays +05:00 </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#12">Console.WriteLine(Date.Now.ToString("%K")) ' Displays -07:00 Console.WriteLine(Date.UtcNow.ToString("%K")) ' Displays Z Console.WriteLine("'{0}'", _ Date.SpecifyKind(Date.Now, _ DateTimeKind.Unspecified). _ ToString("%K")) ' Displays '' Console.WriteLine(DateTimeOffset.Now.ToString("%K")) ' Displays -07:00 Console.WriteLine(DateTimeOffset.UtcNow.ToString("%K")) ' Displays +00:00 Console.WriteLine(New DateTimeOffset(2008, 5, 1, 6, 30, 0, _ New TimeSpan(5, 0, 0)). _ ToString("%K")) ' Displays +05:00 </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h2 id="minute-m-format-specifier">Minute "m" format specifier</h2> <h3 id="mSpecifier"> The "m" custom format specifier</h3> <p>The "m" custom format specifier represents the minute as a number from 0 to 59. The minute represents whole minutes that have passed since the last hour. A single-digit minute is formatted without a leading zero.</p> <p>If the "m" format specifier is used without other custom format specifiers, it's interpreted as the "m" standard date and time format specifier. For more information about using a single format specifier, see <a href="#UsingSingleSpecifiers" data-linktype="self-bookmark">Using Single Custom Format Specifiers</a> later in this article.</p> <p>The following example includes the "m" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#7">DateTime date1; date1 = new DateTime(2008, 1, 1, 18, 9, 1); Console.WriteLine(date1.ToString("h:m:s.F t", CultureInfo.InvariantCulture)); // Displays 6:9:1 P Console.WriteLine(date1.ToString("h:m:s.F t", CultureInfo.CreateSpecificCulture("el-GR"))); // Displays 6:9:1 µ date1 = new DateTime(2008, 1, 1, 18, 9, 1, 500); Console.WriteLine(date1.ToString("h:m:s.F t", CultureInfo.InvariantCulture)); // Displays 6:9:1.5 P Console.WriteLine(date1.ToString("h:m:s.F t", CultureInfo.CreateSpecificCulture("el-GR"))); // Displays 6:9:1.5 µ </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#7">Dim date1 As Date date1 = #6:09:01PM# Console.WriteLine(date1.ToString("h:m:s.F t", _ CultureInfo.InvariantCulture)) ' Displays 6:9:1 P Console.WriteLine(date1.ToString("h:m:s.F t", _ CultureInfo.CreateSpecificCulture("el-GR"))) ' Displays 6:9:1 µ date1 = New Date(2008, 1, 1, 18, 9, 1, 500) Console.WriteLine(date1.ToString("h:m:s.F t", _ CultureInfo.InvariantCulture)) ' Displays 6:9:1.5 P Console.WriteLine(date1.ToString("h:m:s.F t", _ CultureInfo.CreateSpecificCulture("el-GR"))) ' Displays 6:9:1.5 µ </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="mmSpecifier"> The "mm" custom format specifier</h3> <p>The "mm" custom format specifier (plus any number of additional "m" specifiers) represents the minute as a number from 00 to 59. The minute represents whole minutes that have passed since the last hour. A single-digit minute is formatted with a leading zero.</p> <p>The following example includes the "mm" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#8">DateTime date1; date1 = new DateTime(2008, 1, 1, 18, 9, 1); Console.WriteLine(date1.ToString("hh:mm:ss tt", CultureInfo.InvariantCulture)); // Displays 06:09:01 PM Console.WriteLine(date1.ToString("hh:mm:ss tt", CultureInfo.CreateSpecificCulture("hu-HU"))); // Displays 06:09:01 du. date1 = new DateTime(2008, 1, 1, 18, 9, 1, 500); Console.WriteLine(date1.ToString("hh:mm:ss.ff tt", CultureInfo.InvariantCulture)); // Displays 06:09:01.50 PM Console.WriteLine(date1.ToString("hh:mm:ss.ff tt", CultureInfo.CreateSpecificCulture("hu-HU"))); // Displays 06:09:01.50 du. </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#8">Dim date1 As Date date1 = #6:09:01PM# Console.WriteLine(date1.ToString("hh:mm:ss tt", _ CultureInfo.InvariantCulture)) ' Displays 06:09:01 PM Console.WriteLine(date1.ToString("hh:mm:ss tt", _ CultureInfo.CreateSpecificCulture("hu-HU"))) ' Displays 06:09:01 du. date1 = New Date(2008, 1, 1, 18, 9, 1, 500) Console.WriteLine(date1.ToString("hh:mm:ss.ff tt", _ CultureInfo.InvariantCulture)) ' Displays 06:09:01.50 PM Console.WriteLine(date1.ToString("hh:mm:ss.ff tt", _ CultureInfo.CreateSpecificCulture("hu-HU"))) ' Displays 06:09:01.50 du. </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h2 id="month-m-format-specifier">Month "M" format specifier</h2> <h3 id="M_Specifier"> The "M" custom format specifier</h3> <p>The "M" custom format specifier represents the month as a number from 1 to 12 (or from 1 to 13 for calendars that have 13 months). A single-digit month is formatted without a leading zero.</p> <p>If the "M" format specifier is used without other custom format specifiers, it's interpreted as the "M" standard date and time format specifier. For more information about using a single format specifier, see <a href="#UsingSingleSpecifiers" data-linktype="self-bookmark">Using Single Custom Format Specifiers</a> later in this article.</p> <p>The following example includes the "M" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#11">DateTime date1 = new DateTime(2008, 8, 18); Console.WriteLine(date1.ToString("(M) MMM, MMMM", CultureInfo.CreateSpecificCulture("en-US"))); // Displays (8) Aug, August Console.WriteLine(date1.ToString("(M) MMM, MMMM", CultureInfo.CreateSpecificCulture("nl-NL"))); // Displays (8) aug, augustus Console.WriteLine(date1.ToString("(M) MMM, MMMM", CultureInfo.CreateSpecificCulture("lv-LV"))); // Displays (8) Aug, augusts </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#11">Dim date1 As Date = #8/18/2008# Console.WriteLine(date1.ToString("(M) MMM, MMMM", _ CultureInfo.CreateSpecificCulture("en-US"))) ' Displays (8) Aug, August Console.WriteLine(date1.ToString("(M) MMM, MMMM", _ CultureInfo.CreateSpecificCulture("nl-NL"))) ' Displays (8) aug, augustus Console.WriteLine(date1.ToString("(M) MMM, MMMM", _ CultureInfo.CreateSpecificCulture("lv-LV"))) ' Displays (8) Aug, augusts </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="MM_Specifier"> The "MM" custom format specifier</h3> <p>The "MM" custom format specifier represents the month as a number from 01 to 12 (or from 1 to 13 for calendars that have 13 months). A single-digit month is formatted with a leading zero.</p> <p>The following example includes the "MM" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#2">DateTime date1 = new DateTime(2008, 1, 2, 6, 30, 15); Console.WriteLine(date1.ToString("dd, MM", CultureInfo.InvariantCulture)); // 02, 01 </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#2">Dim date1 As Date = #1/2/2008 6:30:15AM# Console.WriteLine(date1.ToString("dd, MM", _ CultureInfo.InvariantCulture)) ' 02, 01 </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="MMM_Specifier"> The "MMM" custom format specifier</h3> <p>The "MMM" custom format specifier represents the abbreviated name of the month. The localized abbreviated name of the month is retrieved from the <a href="/en-us/dotnet/api/system.globalization.datetimeformatinfo.abbreviatedmonthnames" class="no-loc" data-linktype="absolute-path">DateTimeFormatInfo.AbbreviatedMonthNames</a> property of the current or specified culture. If there is a "d" or "dd" custom format specifier in the custom format string, it is retrieved from the <a href="/en-us/dotnet/api/system.globalization.datetimeformatinfo.abbreviatedmonthgenitivenames" class="no-loc" data-linktype="absolute-path">DateTimeFormatInfo.AbbreviatedMonthGenitiveNames</a> property instead.</p> <p>The following example includes the "MMM" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#3">DateTime date1 = new DateTime(2008, 8, 29, 19, 27, 15); Console.WriteLine(date1.ToString("ddd d MMM", CultureInfo.CreateSpecificCulture("en-US"))); // Displays Fri 29 Aug Console.WriteLine(date1.ToString("ddd d MMM", CultureInfo.CreateSpecificCulture("fr-FR"))); // Displays ven. 29 août </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#3">Dim date1 As Date = #08/29/2008 7:27:15PM# Console.WriteLine(date1.ToString("ddd d MMM", _ CultureInfo.CreateSpecificCulture("en-US"))) ' Displays Fri 29 Aug Console.WriteLine(date1.ToString("ddd d MMM", _ CultureInfo.CreateSpecificCulture("fr-FR"))) ' Displays ven. 29 août </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="MMMM_Specifier"> The "MMMM" custom format specifier</h3> <p>The "MMMM" custom format specifier represents the full name of the month. The localized name of the month is retrieved from the <a href="/en-us/dotnet/api/system.globalization.datetimeformatinfo.monthnames" class="no-loc" data-linktype="absolute-path">DateTimeFormatInfo.MonthNames</a> property of the current or specified culture. If there is a "d" or "dd" custom format specifier in the custom format string, it is retrieved from the <a href="/en-us/dotnet/api/system.globalization.datetimeformatinfo.monthgenitivenames" class="no-loc" data-linktype="absolute-path">DateTimeFormatInfo.MonthGenitiveNames</a> property instead.</p> <p>The following example includes the "MMMM" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#4">DateTime date1 = new DateTime(2008, 8, 29, 19, 27, 15); Console.WriteLine(date1.ToString("dddd dd MMMM", CultureInfo.CreateSpecificCulture("en-US"))); // Displays Friday 29 August Console.WriteLine(date1.ToString("dddd dd MMMM", CultureInfo.CreateSpecificCulture("it-IT"))); // Displays venerdì 29 agosto </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#4">Dim date1 As Date = #08/29/2008 7:27:15PM# Console.WriteLine(date1.ToString("dddd dd MMMM", _ CultureInfo.CreateSpecificCulture("en-US"))) ' Displays Friday 29 August Console.WriteLine(date1.ToString("dddd dd MMMM", _ CultureInfo.CreateSpecificCulture("it-IT"))) ' Displays venerdì 29 agosto </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h2 id="seconds-s-format-specifier">Seconds "s" format specifier</h2> <h3 id="sSpecifier"> The "s" custom format specifier</h3> <p>The "s" custom format specifier represents the seconds as a number from 0 to 59. The result represents whole seconds that have passed since the last minute. A single-digit second is formatted without a leading zero.</p> <p>If the "s" format specifier is used without other custom format specifiers, it's interpreted as the "s" standard date and time format specifier. For more information about using a single format specifier, see <a href="#UsingSingleSpecifiers" data-linktype="self-bookmark">Using Single Custom Format Specifiers</a> later in this article.</p> <p>The following example includes the "s" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#7">DateTime date1; date1 = new DateTime(2008, 1, 1, 18, 9, 1); Console.WriteLine(date1.ToString("h:m:s.F t", CultureInfo.InvariantCulture)); // Displays 6:9:1 P Console.WriteLine(date1.ToString("h:m:s.F t", CultureInfo.CreateSpecificCulture("el-GR"))); // Displays 6:9:1 µ date1 = new DateTime(2008, 1, 1, 18, 9, 1, 500); Console.WriteLine(date1.ToString("h:m:s.F t", CultureInfo.InvariantCulture)); // Displays 6:9:1.5 P Console.WriteLine(date1.ToString("h:m:s.F t", CultureInfo.CreateSpecificCulture("el-GR"))); // Displays 6:9:1.5 µ </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#7">Dim date1 As Date date1 = #6:09:01PM# Console.WriteLine(date1.ToString("h:m:s.F t", _ CultureInfo.InvariantCulture)) ' Displays 6:9:1 P Console.WriteLine(date1.ToString("h:m:s.F t", _ CultureInfo.CreateSpecificCulture("el-GR"))) ' Displays 6:9:1 µ date1 = New Date(2008, 1, 1, 18, 9, 1, 500) Console.WriteLine(date1.ToString("h:m:s.F t", _ CultureInfo.InvariantCulture)) ' Displays 6:9:1.5 P Console.WriteLine(date1.ToString("h:m:s.F t", _ CultureInfo.CreateSpecificCulture("el-GR"))) ' Displays 6:9:1.5 µ </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="ssSpecifier"> The "ss" custom format specifier</h3> <p>The "ss" custom format specifier (plus any number of additional "s" specifiers) represents the seconds as a number from 00 to 59. The result represents whole seconds that have passed since the last minute. A single-digit second is formatted with a leading zero.</p> <p>The following example includes the "ss" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#8">DateTime date1; date1 = new DateTime(2008, 1, 1, 18, 9, 1); Console.WriteLine(date1.ToString("hh:mm:ss tt", CultureInfo.InvariantCulture)); // Displays 06:09:01 PM Console.WriteLine(date1.ToString("hh:mm:ss tt", CultureInfo.CreateSpecificCulture("hu-HU"))); // Displays 06:09:01 du. date1 = new DateTime(2008, 1, 1, 18, 9, 1, 500); Console.WriteLine(date1.ToString("hh:mm:ss.ff tt", CultureInfo.InvariantCulture)); // Displays 06:09:01.50 PM Console.WriteLine(date1.ToString("hh:mm:ss.ff tt", CultureInfo.CreateSpecificCulture("hu-HU"))); // Displays 06:09:01.50 du. </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#8">Dim date1 As Date date1 = #6:09:01PM# Console.WriteLine(date1.ToString("hh:mm:ss tt", _ CultureInfo.InvariantCulture)) ' Displays 06:09:01 PM Console.WriteLine(date1.ToString("hh:mm:ss tt", _ CultureInfo.CreateSpecificCulture("hu-HU"))) ' Displays 06:09:01 du. date1 = New Date(2008, 1, 1, 18, 9, 1, 500) Console.WriteLine(date1.ToString("hh:mm:ss.ff tt", _ CultureInfo.InvariantCulture)) ' Displays 06:09:01.50 PM Console.WriteLine(date1.ToString("hh:mm:ss.ff tt", _ CultureInfo.CreateSpecificCulture("hu-HU"))) ' Displays 06:09:01.50 du. </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h2 id="meridiem-t-format-specifier">Meridiem "t" format specifier</h2> <h3 id="tSpecifier"> The "t" custom format specifier</h3> <p>The "t" custom format specifier represents the first character of the AM/PM designator. The appropriate localized designator is retrieved from the <a href="/en-us/dotnet/api/system.globalization.datetimeformatinfo.amdesignator" class="no-loc" data-linktype="absolute-path">DateTimeFormatInfo.AMDesignator</a> or <a href="/en-us/dotnet/api/system.globalization.datetimeformatinfo.pmdesignator" class="no-loc" data-linktype="absolute-path">DateTimeFormatInfo.PMDesignator</a> property of the current or specific culture. The AM designator is used for all times from 0:00:00 (midnight) to 11:59:59.999. The PM designator is used for all times from 12:00:00 (noon) to 23:59:59.999.</p> <p>If the "t" format specifier is used without other custom format specifiers, it's interpreted as the "t" standard date and time format specifier. For more information about using a single format specifier, see <a href="#UsingSingleSpecifiers" data-linktype="self-bookmark">Using Single Custom Format Specifiers</a> later in this article.</p> <p>The following example includes the "t" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#7">DateTime date1; date1 = new DateTime(2008, 1, 1, 18, 9, 1); Console.WriteLine(date1.ToString("h:m:s.F t", CultureInfo.InvariantCulture)); // Displays 6:9:1 P Console.WriteLine(date1.ToString("h:m:s.F t", CultureInfo.CreateSpecificCulture("el-GR"))); // Displays 6:9:1 µ date1 = new DateTime(2008, 1, 1, 18, 9, 1, 500); Console.WriteLine(date1.ToString("h:m:s.F t", CultureInfo.InvariantCulture)); // Displays 6:9:1.5 P Console.WriteLine(date1.ToString("h:m:s.F t", CultureInfo.CreateSpecificCulture("el-GR"))); // Displays 6:9:1.5 µ </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#7">Dim date1 As Date date1 = #6:09:01PM# Console.WriteLine(date1.ToString("h:m:s.F t", _ CultureInfo.InvariantCulture)) ' Displays 6:9:1 P Console.WriteLine(date1.ToString("h:m:s.F t", _ CultureInfo.CreateSpecificCulture("el-GR"))) ' Displays 6:9:1 µ date1 = New Date(2008, 1, 1, 18, 9, 1, 500) Console.WriteLine(date1.ToString("h:m:s.F t", _ CultureInfo.InvariantCulture)) ' Displays 6:9:1.5 P Console.WriteLine(date1.ToString("h:m:s.F t", _ CultureInfo.CreateSpecificCulture("el-GR"))) ' Displays 6:9:1.5 µ </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="ttSpecifier"> The "tt" custom format specifier</h3> <p>The "tt" custom format specifier (plus any number of additional "t" specifiers) represents the entire AM/PM designator. The appropriate localized designator is retrieved from the <a href="/en-us/dotnet/api/system.globalization.datetimeformatinfo.amdesignator" class="no-loc" data-linktype="absolute-path">DateTimeFormatInfo.AMDesignator</a> or <a href="/en-us/dotnet/api/system.globalization.datetimeformatinfo.pmdesignator" class="no-loc" data-linktype="absolute-path">DateTimeFormatInfo.PMDesignator</a> property of the current or specific culture. The AM designator is used for all times from 0:00:00 (midnight) to 11:59:59.999. The PM designator is used for all times from 12:00:00 (noon) to 23:59:59.999.</p> <p>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.</p> <p>The following example includes the "tt" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#8">DateTime date1; date1 = new DateTime(2008, 1, 1, 18, 9, 1); Console.WriteLine(date1.ToString("hh:mm:ss tt", CultureInfo.InvariantCulture)); // Displays 06:09:01 PM Console.WriteLine(date1.ToString("hh:mm:ss tt", CultureInfo.CreateSpecificCulture("hu-HU"))); // Displays 06:09:01 du. date1 = new DateTime(2008, 1, 1, 18, 9, 1, 500); Console.WriteLine(date1.ToString("hh:mm:ss.ff tt", CultureInfo.InvariantCulture)); // Displays 06:09:01.50 PM Console.WriteLine(date1.ToString("hh:mm:ss.ff tt", CultureInfo.CreateSpecificCulture("hu-HU"))); // Displays 06:09:01.50 du. </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#8">Dim date1 As Date date1 = #6:09:01PM# Console.WriteLine(date1.ToString("hh:mm:ss tt", _ CultureInfo.InvariantCulture)) ' Displays 06:09:01 PM Console.WriteLine(date1.ToString("hh:mm:ss tt", _ CultureInfo.CreateSpecificCulture("hu-HU"))) ' Displays 06:09:01 du. date1 = New Date(2008, 1, 1, 18, 9, 1, 500) Console.WriteLine(date1.ToString("hh:mm:ss.ff tt", _ CultureInfo.InvariantCulture)) ' Displays 06:09:01.50 PM Console.WriteLine(date1.ToString("hh:mm:ss.ff tt", _ CultureInfo.CreateSpecificCulture("hu-HU"))) ' Displays 06:09:01.50 du. </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h2 id="year-y-format-specifier">Year "y" format specifier</h2> <h3 id="ySpecifier"> The "y" custom format specifier</h3> <p>The "y" custom format specifier represents the year as a one-digit or two-digit number. If the year has more than two digits, only the two low-order digits appear in the result. If the first digit of a two-digit year begins with a zero (for example, 2008), the number is formatted without a leading zero.</p> <p>If the "y" format specifier is used without other custom format specifiers, it's interpreted as the "y" standard date and time format specifier. For more information about using a single format specifier, see <a href="#UsingSingleSpecifiers" data-linktype="self-bookmark">Using Single Custom Format Specifiers</a> later in this article.</p> <p>The following example includes the "y" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" data-interactive="csharp" name="Formatting.DateAndTime.Custom#13">DateTime date1 = new DateTime(1, 12, 1); DateTime date2 = new DateTime(2010, 1, 1); Console.WriteLine(date1.ToString("%y")); // Displays 1 Console.WriteLine(date1.ToString("yy")); // Displays 01 Console.WriteLine(date1.ToString("yyy")); // Displays 001 Console.WriteLine(date1.ToString("yyyy")); // Displays 0001 Console.WriteLine(date1.ToString("yyyyy")); // Displays 00001 Console.WriteLine(date2.ToString("%y")); // Displays 10 Console.WriteLine(date2.ToString("yy")); // Displays 10 Console.WriteLine(date2.ToString("yyy")); // Displays 2010 Console.WriteLine(date2.ToString("yyyy")); // Displays 2010 Console.WriteLine(date2.ToString("yyyyy")); // Displays 02010 </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#13">Dim date1 As Date = #12/1/0001# Dim date2 As Date = #1/1/2010# Console.WriteLine(date1.ToString("%y")) ' Displays 1 Console.WriteLine(date1.ToString("yy")) ' Displays 01 Console.WriteLine(date1.ToString("yyy")) ' Displays 001 Console.WriteLine(date1.ToString("yyyy")) ' Displays 0001 Console.WriteLine(date1.ToString("yyyyy")) ' Displays 00001 Console.WriteLine(date2.ToString("%y")) ' Displays 10 Console.WriteLine(date2.ToString("yy")) ' Displays 10 Console.WriteLine(date2.ToString("yyy")) ' Displays 2010 Console.WriteLine(date2.ToString("yyyy")) ' Displays 2010 Console.WriteLine(date2.ToString("yyyyy")) ' Displays 02010 </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="yySpecifier"> The "yy" custom format specifier</h3> <p>The "yy" custom format specifier represents the year as a two-digit number. If the year has more than two digits, only the two low-order digits appear in the result. If the two-digit year has fewer than two significant digits, the number is padded with leading zeros to produce two digits.</p> <p>In a parsing operation, a two-digit year that is parsed using the "yy" custom format specifier is interpreted based on the <a href="/en-us/dotnet/api/system.globalization.calendar.twodigityearmax" class="no-loc" data-linktype="absolute-path">Calendar.TwoDigitYearMax</a> property of the format provider's current calendar. The following example parses the string representation of a date that has a two-digit year by using the default Gregorian calendar of the en-US culture, which, in this case, is the current culture. It then changes the current culture's <a href="/en-us/dotnet/api/system.globalization.cultureinfo" class="no-loc" data-linktype="absolute-path">CultureInfo</a> object to use a <a href="/en-us/dotnet/api/system.globalization.gregoriancalendar" class="no-loc" data-linktype="absolute-path">GregorianCalendar</a> object whose <a href="/en-us/dotnet/api/system.globalization.gregoriancalendar.twodigityearmax" class="no-loc" data-linktype="absolute-path">TwoDigitYearMax</a> property has been modified.</p> <pre><code class="lang-csharp" data-interactive="csharp" name="Formatting.DateAndTime.Custom#19">using System; using System.Globalization; using System.Threading; public class Example7 { public static void Main() { string fmt = "dd-MMM-yy"; string value = "24-Jan-49"; Calendar cal = (Calendar)CultureInfo.CurrentCulture.Calendar.Clone(); Console.WriteLine("Two Digit Year Range: {0} - {1}", cal.TwoDigitYearMax - 99, cal.TwoDigitYearMax); Console.WriteLine("{0:d}", DateTime.ParseExact(value, fmt, null)); Console.WriteLine(); cal.TwoDigitYearMax = 2099; CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone(); culture.DateTimeFormat.Calendar = cal; Thread.CurrentThread.CurrentCulture = culture; Console.WriteLine("Two Digit Year Range: {0} - {1}", cal.TwoDigitYearMax - 99, cal.TwoDigitYearMax); Console.WriteLine("{0:d}", DateTime.ParseExact(value, fmt, null)); } } // The example displays the following output: // Two Digit Year Range: 1930 - 2029 // 1/24/1949 // // Two Digit Year Range: 2000 - 2099 // 1/24/2049 </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#19">Imports System.Globalization Imports System.Threading Module Example Public Sub Main() Dim fmt As String = "dd-MMM-yy" Dim value As String = "24-Jan-49" Dim cal As Calendar = CType(CultureInfo.CurrentCulture.Calendar.Clone(), Calendar) Console.WriteLine("Two Digit Year Range: {0} - {1}", cal.TwoDigitYearMax - 99, cal.TwoDigitYearMax) Console.WriteLine("{0:d}", DateTime.ParseExact(value, fmt, Nothing)) Console.WriteLine() cal.TwoDigitYearMax = 2099 Dim culture As CultureInfo = CType(CultureInfo.CurrentCulture.Clone(), CultureInfo) culture.DateTimeFormat.Calendar = cal Thread.CurrentThread.CurrentCulture = culture Console.WriteLine("Two Digit Year Range: {0} - {1}", cal.TwoDigitYearMax - 99, cal.TwoDigitYearMax) Console.WriteLine("{0:d}", DateTime.ParseExact(value, fmt, Nothing)) End Sub End Module ' The example displays the following output: ' Two Digit Year Range: 1930 - 2029 ' 1/24/1949 ' ' Two Digit Year Range: 2000 - 2099 ' 1/24/2049 </code></pre> <p>The following example includes the "yy" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#13">DateTime date1 = new DateTime(1, 12, 1); DateTime date2 = new DateTime(2010, 1, 1); Console.WriteLine(date1.ToString("%y")); // Displays 1 Console.WriteLine(date1.ToString("yy")); // Displays 01 Console.WriteLine(date1.ToString("yyy")); // Displays 001 Console.WriteLine(date1.ToString("yyyy")); // Displays 0001 Console.WriteLine(date1.ToString("yyyyy")); // Displays 00001 Console.WriteLine(date2.ToString("%y")); // Displays 10 Console.WriteLine(date2.ToString("yy")); // Displays 10 Console.WriteLine(date2.ToString("yyy")); // Displays 2010 Console.WriteLine(date2.ToString("yyyy")); // Displays 2010 Console.WriteLine(date2.ToString("yyyyy")); // Displays 02010 </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#13">Dim date1 As Date = #12/1/0001# Dim date2 As Date = #1/1/2010# Console.WriteLine(date1.ToString("%y")) ' Displays 1 Console.WriteLine(date1.ToString("yy")) ' Displays 01 Console.WriteLine(date1.ToString("yyy")) ' Displays 001 Console.WriteLine(date1.ToString("yyyy")) ' Displays 0001 Console.WriteLine(date1.ToString("yyyyy")) ' Displays 00001 Console.WriteLine(date2.ToString("%y")) ' Displays 10 Console.WriteLine(date2.ToString("yy")) ' Displays 10 Console.WriteLine(date2.ToString("yyy")) ' Displays 2010 Console.WriteLine(date2.ToString("yyyy")) ' Displays 2010 Console.WriteLine(date2.ToString("yyyyy")) ' Displays 02010 </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="yyySpecifier"> The "yyy" custom format specifier</h3> <p>The "yyy" custom format specifier represents the year with a minimum of three digits. If the year has more than three significant digits, they are included in the result string. If the year has fewer than three digits, the number is padded with leading zeros to produce three digits.</p> <div class="NOTE"> <p>Note</p> <p>For the Thai Buddhist calendar, which can have five-digit years, this format specifier displays all significant digits.</p> </div> <p>The following example includes the "yyy" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" data-interactive="csharp" name="Formatting.DateAndTime.Custom#13">DateTime date1 = new DateTime(1, 12, 1); DateTime date2 = new DateTime(2010, 1, 1); Console.WriteLine(date1.ToString("%y")); // Displays 1 Console.WriteLine(date1.ToString("yy")); // Displays 01 Console.WriteLine(date1.ToString("yyy")); // Displays 001 Console.WriteLine(date1.ToString("yyyy")); // Displays 0001 Console.WriteLine(date1.ToString("yyyyy")); // Displays 00001 Console.WriteLine(date2.ToString("%y")); // Displays 10 Console.WriteLine(date2.ToString("yy")); // Displays 10 Console.WriteLine(date2.ToString("yyy")); // Displays 2010 Console.WriteLine(date2.ToString("yyyy")); // Displays 2010 Console.WriteLine(date2.ToString("yyyyy")); // Displays 02010 </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#13">Dim date1 As Date = #12/1/0001# Dim date2 As Date = #1/1/2010# Console.WriteLine(date1.ToString("%y")) ' Displays 1 Console.WriteLine(date1.ToString("yy")) ' Displays 01 Console.WriteLine(date1.ToString("yyy")) ' Displays 001 Console.WriteLine(date1.ToString("yyyy")) ' Displays 0001 Console.WriteLine(date1.ToString("yyyyy")) ' Displays 00001 Console.WriteLine(date2.ToString("%y")) ' Displays 10 Console.WriteLine(date2.ToString("yy")) ' Displays 10 Console.WriteLine(date2.ToString("yyy")) ' Displays 2010 Console.WriteLine(date2.ToString("yyyy")) ' Displays 2010 Console.WriteLine(date2.ToString("yyyyy")) ' Displays 02010 </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="yyyySpecifier"> The "yyyy" custom format specifier</h3> <p>The "yyyy" custom format specifier represents the year with a minimum of four digits. If the year has more than four significant digits, they are included in the result string. If the year has fewer than four digits, the number is padded with leading zeros to produce four digits.</p> <div class="NOTE"> <p>Note</p> <p>For the Thai Buddhist calendar, which can have five-digit years, this format specifier displays a minimum of four digits.</p> </div> <p>The following example includes the "yyyy" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" data-interactive="csharp" name="Formatting.DateAndTime.Custom#13">DateTime date1 = new DateTime(1, 12, 1); DateTime date2 = new DateTime(2010, 1, 1); Console.WriteLine(date1.ToString("%y")); // Displays 1 Console.WriteLine(date1.ToString("yy")); // Displays 01 Console.WriteLine(date1.ToString("yyy")); // Displays 001 Console.WriteLine(date1.ToString("yyyy")); // Displays 0001 Console.WriteLine(date1.ToString("yyyyy")); // Displays 00001 Console.WriteLine(date2.ToString("%y")); // Displays 10 Console.WriteLine(date2.ToString("yy")); // Displays 10 Console.WriteLine(date2.ToString("yyy")); // Displays 2010 Console.WriteLine(date2.ToString("yyyy")); // Displays 2010 Console.WriteLine(date2.ToString("yyyyy")); // Displays 02010 </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#13">Dim date1 As Date = #12/1/0001# Dim date2 As Date = #1/1/2010# Console.WriteLine(date1.ToString("%y")) ' Displays 1 Console.WriteLine(date1.ToString("yy")) ' Displays 01 Console.WriteLine(date1.ToString("yyy")) ' Displays 001 Console.WriteLine(date1.ToString("yyyy")) ' Displays 0001 Console.WriteLine(date1.ToString("yyyyy")) ' Displays 00001 Console.WriteLine(date2.ToString("%y")) ' Displays 10 Console.WriteLine(date2.ToString("yy")) ' Displays 10 Console.WriteLine(date2.ToString("yyy")) ' Displays 2010 Console.WriteLine(date2.ToString("yyyy")) ' Displays 2010 Console.WriteLine(date2.ToString("yyyyy")) ' Displays 02010 </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="yyyyySpecifier"> The "yyyyy" custom format specifier</h3> <p>The "yyyyy" custom format specifier (plus any number of additional "y" specifiers) represents the year with a minimum of five digits. If the year has more than five significant digits, they are included in the result string. If the year has fewer than five digits, the number is padded with leading zeros to produce five digits.</p> <p>If there are additional "y" specifiers, the number is padded with as many leading zeros as necessary to produce the number of "y" specifiers.</p> <p>The following example includes the "yyyyy" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" data-interactive="csharp" name="Formatting.DateAndTime.Custom#13">DateTime date1 = new DateTime(1, 12, 1); DateTime date2 = new DateTime(2010, 1, 1); Console.WriteLine(date1.ToString("%y")); // Displays 1 Console.WriteLine(date1.ToString("yy")); // Displays 01 Console.WriteLine(date1.ToString("yyy")); // Displays 001 Console.WriteLine(date1.ToString("yyyy")); // Displays 0001 Console.WriteLine(date1.ToString("yyyyy")); // Displays 00001 Console.WriteLine(date2.ToString("%y")); // Displays 10 Console.WriteLine(date2.ToString("yy")); // Displays 10 Console.WriteLine(date2.ToString("yyy")); // Displays 2010 Console.WriteLine(date2.ToString("yyyy")); // Displays 2010 Console.WriteLine(date2.ToString("yyyyy")); // Displays 02010 </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#13">Dim date1 As Date = #12/1/0001# Dim date2 As Date = #1/1/2010# Console.WriteLine(date1.ToString("%y")) ' Displays 1 Console.WriteLine(date1.ToString("yy")) ' Displays 01 Console.WriteLine(date1.ToString("yyy")) ' Displays 001 Console.WriteLine(date1.ToString("yyyy")) ' Displays 0001 Console.WriteLine(date1.ToString("yyyyy")) ' Displays 00001 Console.WriteLine(date2.ToString("%y")) ' Displays 10 Console.WriteLine(date2.ToString("yy")) ' Displays 10 Console.WriteLine(date2.ToString("yyy")) ' Displays 2010 Console.WriteLine(date2.ToString("yyyy")) ' Displays 2010 Console.WriteLine(date2.ToString("yyyyy")) ' Displays 02010 </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h2 id="offset-z-format-specifier">Offset "z" format specifier</h2> <h3 id="zSpecifier"> The "z" custom format specifier</h3> <p>With <a href="/en-us/dotnet/api/system.datetime" class="no-loc" data-linktype="absolute-path">DateTime</a> values, the "z" custom format specifier represents the signed offset of the specified time zone from Coordinated Universal Time (UTC), measured in hours. The offset is always displayed with a leading sign. A plus sign (+) indicates hours ahead of UTC, and a minus sign (-) indicates hours behind UTC. A single-digit offset is formatted <em>without</em> a leading zero.</p> <p>The following table shows how the offset value changes depending on <a href="/en-us/dotnet/api/system.datetimekind" class="no-loc" data-linktype="absolute-path">DateTimeKind</a>.</p> <table> <thead> <tr> <th><a href="/en-us/dotnet/api/system.datetimekind" class="no-loc" data-linktype="absolute-path">DateTimeKind</a> value</th> <th>Offset value</th> </tr> </thead> <tbody> <tr> <td><a href="/en-us/dotnet/api/system.datetimekind#system-datetimekind-local" class="no-loc" data-linktype="absolute-path">Local</a></td> <td>The signed offset of the local operating system's time zone from UTC.</td> </tr> <tr> <td><a href="/en-us/dotnet/api/system.datetimekind#system-datetimekind-unspecified" class="no-loc" data-linktype="absolute-path">Unspecified</a></td> <td>The signed offset of the local operating system's time zone from UTC.</td> </tr> <tr> <td><a href="/en-us/dotnet/api/system.datetimekind#system-datetimekind-utc" class="no-loc" data-linktype="absolute-path">Utc</a></td> <td><code>+0</code> on .NET Core and .NET 5+. <br><br> On .NET Framework, the signed offset of the local operating system's time zone from UTC.</td> </tr> </tbody> </table> <p>With <a href="/en-us/dotnet/api/system.datetimeoffset" class="no-loc" data-linktype="absolute-path">DateTimeOffset</a> values, this format specifier represents the <a href="/en-us/dotnet/api/system.datetimeoffset" class="no-loc" data-linktype="absolute-path">DateTimeOffset</a> value's offset from UTC in hours.</p> <p>If the "z" format specifier is used without other custom format specifiers, it's interpreted as a standard date and time format specifier and throws a <a href="/en-us/dotnet/api/system.formatexception" class="no-loc" data-linktype="absolute-path">FormatException</a>. For more information about using a single format specifier, see <a href="#UsingSingleSpecifiers" data-linktype="self-bookmark">Using Single Custom Format Specifiers</a> later in this article.</p> <p>The following example includes the "z" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" data-interactive="csharp" name="Formatting.DateAndTime.Custom#14">DateTime date1 = DateTime.UtcNow; Console.WriteLine(String.Format("{0:%z}, {0:zz}, {0:zzz}", date1)); // Displays -7, -07, -07:00 on .NET Framework // Displays +0, +00, +00:00 on .NET Core and .NET 5+ DateTimeOffset date2 = new DateTimeOffset(2008, 8, 1, 0, 0, 0, new TimeSpan(6, 0, 0)); Console.WriteLine(String.Format("{0:%z}, {0:zz}, {0:zzz}", date2)); // Displays +6, +06, +06:00 </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#14">Dim date1 As Date = Date.UtcNow Console.WriteLine(String.Format("{0:%z}, {0:zz}, {0:zzz}", _ date1)) ' Displays -7, -07, -07:00 on .NET Framework ' Displays +0, +00, +00:00 on .NET Core and .NET 5+ Dim date2 As New DateTimeOffset(2008, 8, 1, 0, 0, 0, _ New Timespan(6, 0, 0)) Console.WriteLine(String.Format("{0:%z}, {0:zz}, {0:zzz}", _ date2)) ' Displays +6, +06, +06:00 </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="zzSpecifier"> The "zz" custom format specifier</h3> <p>With <a href="/en-us/dotnet/api/system.datetime" class="no-loc" data-linktype="absolute-path">DateTime</a> values, the "zz" custom format specifier represents the signed offset of the specified time zone from UTC, measured in hours. The offset is always displayed with a leading sign. A plus sign (+) indicates hours ahead of UTC, and a minus sign (-) indicates hours behind UTC. A single-digit offset is formatted <em>with</em> a leading zero.</p> <p>The following table shows how the offset value changes depending on <a href="/en-us/dotnet/api/system.datetimekind" class="no-loc" data-linktype="absolute-path">DateTimeKind</a>.</p> <table> <thead> <tr> <th><a href="/en-us/dotnet/api/system.datetimekind" class="no-loc" data-linktype="absolute-path">DateTimeKind</a> value</th> <th>Offset value</th> </tr> </thead> <tbody> <tr> <td><a href="/en-us/dotnet/api/system.datetimekind#system-datetimekind-local" class="no-loc" data-linktype="absolute-path">Local</a></td> <td>The signed offset of the local operating system's time zone from UTC.</td> </tr> <tr> <td><a href="/en-us/dotnet/api/system.datetimekind#system-datetimekind-unspecified" class="no-loc" data-linktype="absolute-path">Unspecified</a></td> <td>The signed offset of the local operating system's time zone from UTC.</td> </tr> <tr> <td><a href="/en-us/dotnet/api/system.datetimekind#system-datetimekind-utc" class="no-loc" data-linktype="absolute-path">Utc</a></td> <td><code>+00</code> on .NET Core and .NET 5+. <br><br> On .NET Framework, the signed offset of the local operating system's time zone from UTC.</td> </tr> </tbody> </table> <p>With <a href="/en-us/dotnet/api/system.datetimeoffset" class="no-loc" data-linktype="absolute-path">DateTimeOffset</a> values, this format specifier represents the <a href="/en-us/dotnet/api/system.datetimeoffset" class="no-loc" data-linktype="absolute-path">DateTimeOffset</a> value's offset from UTC in hours.</p> <p>The following example includes the "zz" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" data-interactive="csharp" name="Formatting.DateAndTime.Custom#14">DateTime date1 = DateTime.UtcNow; Console.WriteLine(String.Format("{0:%z}, {0:zz}, {0:zzz}", date1)); // Displays -7, -07, -07:00 on .NET Framework // Displays +0, +00, +00:00 on .NET Core and .NET 5+ DateTimeOffset date2 = new DateTimeOffset(2008, 8, 1, 0, 0, 0, new TimeSpan(6, 0, 0)); Console.WriteLine(String.Format("{0:%z}, {0:zz}, {0:zzz}", date2)); // Displays +6, +06, +06:00 </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#14">Dim date1 As Date = Date.UtcNow Console.WriteLine(String.Format("{0:%z}, {0:zz}, {0:zzz}", _ date1)) ' Displays -7, -07, -07:00 on .NET Framework ' Displays +0, +00, +00:00 on .NET Core and .NET 5+ Dim date2 As New DateTimeOffset(2008, 8, 1, 0, 0, 0, _ New Timespan(6, 0, 0)) Console.WriteLine(String.Format("{0:%z}, {0:zz}, {0:zzz}", _ date2)) ' Displays +6, +06, +06:00 </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="zzzSpecifier"> The "zzz" custom format specifier</h3> <p>With <a href="/en-us/dotnet/api/system.datetime" class="no-loc" data-linktype="absolute-path">DateTime</a> values, the "zzz" custom format specifier represents the signed offset of the specified time zone from UTC, measured in hours and minutes. The offset is always displayed with a leading sign. A plus sign (+) indicates hours ahead of UTC, and a minus sign (-) indicates hours behind UTC. A single-digit offset is formatted with a leading zero.</p> <p>The following table shows how the offset value changes depending on <a href="/en-us/dotnet/api/system.datetimekind" class="no-loc" data-linktype="absolute-path">DateTimeKind</a>.</p> <table> <thead> <tr> <th><a href="/en-us/dotnet/api/system.datetimekind" class="no-loc" data-linktype="absolute-path">DateTimeKind</a> value</th> <th>Offset value</th> </tr> </thead> <tbody> <tr> <td><a href="/en-us/dotnet/api/system.datetimekind#system-datetimekind-local" class="no-loc" data-linktype="absolute-path">Local</a></td> <td>The signed offset of the local operating system's time zone from UTC.</td> </tr> <tr> <td><a href="/en-us/dotnet/api/system.datetimekind#system-datetimekind-unspecified" class="no-loc" data-linktype="absolute-path">Unspecified</a></td> <td>The signed offset of the local operating system's time zone from UTC.</td> </tr> <tr> <td><a href="/en-us/dotnet/api/system.datetimekind#system-datetimekind-utc" class="no-loc" data-linktype="absolute-path">Utc</a></td> <td><code>+00:00</code> on .NET Core and .NET 5+. <br><br> On .NET Framework, the signed offset of the local operating system's time zone from UTC.</td> </tr> </tbody> </table> <p>With <a href="/en-us/dotnet/api/system.datetimeoffset" class="no-loc" data-linktype="absolute-path">DateTimeOffset</a> values, this format specifier represents the <a href="/en-us/dotnet/api/system.datetimeoffset" class="no-loc" data-linktype="absolute-path">DateTimeOffset</a> value's offset from UTC in hours and minutes.</p> <p>The following example includes the "zzz" custom format specifier in a custom format string.</p> <pre><code class="lang-csharp" data-interactive="csharp" name="Formatting.DateAndTime.Custom#14">DateTime date1 = DateTime.UtcNow; Console.WriteLine(String.Format("{0:%z}, {0:zz}, {0:zzz}", date1)); // Displays -7, -07, -07:00 on .NET Framework // Displays +0, +00, +00:00 on .NET Core and .NET 5+ DateTimeOffset date2 = new DateTimeOffset(2008, 8, 1, 0, 0, 0, new TimeSpan(6, 0, 0)); Console.WriteLine(String.Format("{0:%z}, {0:zz}, {0:zzz}", date2)); // Displays +6, +06, +06:00 </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#14">Dim date1 As Date = Date.UtcNow Console.WriteLine(String.Format("{0:%z}, {0:zz}, {0:zzz}", _ date1)) ' Displays -7, -07, -07:00 on .NET Framework ' Displays +0, +00, +00:00 on .NET Core and .NET 5+ Dim date2 As New DateTimeOffset(2008, 8, 1, 0, 0, 0, _ New Timespan(6, 0, 0)) Console.WriteLine(String.Format("{0:%z}, {0:zz}, {0:zzz}", _ date2)) ' Displays +6, +06, +06:00 </code></pre> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h2 id="date-and-time-separator-specifiers">Date and time separator specifiers</h2> <h3 id="timeSeparator"> The ":" custom format specifier</h3> <p>The ":" custom format specifier represents the time separator, which is used to differentiate hours, minutes, and seconds. The appropriate localized time separator is retrieved from the <a href="/en-us/dotnet/api/system.globalization.datetimeformatinfo.timeseparator" class="no-loc" data-linktype="absolute-path">DateTimeFormatInfo.TimeSeparator</a> property of the current or specified culture.</p> <div class="NOTE"> <p>Note</p> <p>To change the time separator for a particular date and time string, specify the separator character within a literal string delimiter. For example, the custom format string <code>hh'_'dd'_'ss</code> produces a result string in which "_" (an underscore) is always used as the time separator. To change the time separator for all dates for a culture, either change the value of the <a href="/en-us/dotnet/api/system.globalization.datetimeformatinfo.timeseparator" class="no-loc" data-linktype="absolute-path">DateTimeFormatInfo.TimeSeparator</a> property of the current culture, or instantiate a <a href="/en-us/dotnet/api/system.globalization.datetimeformatinfo" class="no-loc" data-linktype="absolute-path">DateTimeFormatInfo</a> object, assign the character to its <a href="/en-us/dotnet/api/system.globalization.datetimeformatinfo.timeseparator" class="no-loc" data-linktype="absolute-path">TimeSeparator</a> property, and call an overload of the formatting method that includes an <a href="/en-us/dotnet/api/system.iformatprovider" class="no-loc" data-linktype="absolute-path">IFormatProvider</a> parameter.</p> </div> <p>If the ":" format specifier is used without other custom format specifiers, it's interpreted as a standard date and time format specifier and throws a <a href="/en-us/dotnet/api/system.formatexception" class="no-loc" data-linktype="absolute-path">FormatException</a>. For more information about using a single format specifier, see <a href="#UsingSingleSpecifiers" data-linktype="self-bookmark">Using Single Custom Format Specifiers</a> later in this article.</p> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h3 id="dateSeparator"> The "/" custom format specifier</h3> <p>The "/" custom format specifier represents the date separator, which is used to differentiate years, months, and days. The appropriate localized date separator is retrieved from the <a href="/en-us/dotnet/api/system.globalization.datetimeformatinfo.dateseparator" class="no-loc" data-linktype="absolute-path">DateTimeFormatInfo.DateSeparator</a> property of the current or specified culture.</p> <div class="NOTE"> <p>Note</p> <p>To change the date separator for a particular date and time string, specify the separator character within a literal string delimiter. For example, the custom format string <code>mm'/'dd'/'yyyy</code> produces a result string in which "/" is always used as the date separator. To change the date separator for all dates for a culture, either change the value of the <a href="/en-us/dotnet/api/system.globalization.datetimeformatinfo.dateseparator" class="no-loc" data-linktype="absolute-path">DateTimeFormatInfo.DateSeparator</a> property of the current culture, or instantiate a <a href="/en-us/dotnet/api/system.globalization.datetimeformatinfo" class="no-loc" data-linktype="absolute-path">DateTimeFormatInfo</a> object, assign the character to its <a href="/en-us/dotnet/api/system.globalization.datetimeformatinfo.dateseparator" class="no-loc" data-linktype="absolute-path">DateSeparator</a> property, and call an overload of the formatting method that includes an <a href="/en-us/dotnet/api/system.iformatprovider" class="no-loc" data-linktype="absolute-path">IFormatProvider</a> parameter.</p> </div> <p>If the "/" format specifier is used without other custom format specifiers, it's interpreted as a standard date and time format specifier and throws a <a href="/en-us/dotnet/api/system.formatexception" class="no-loc" data-linktype="absolute-path">FormatException</a>. For more information about using a single format specifier, see <a href="#UsingSingleSpecifiers" data-linktype="self-bookmark">Using Single Custom Format Specifiers</a> later in this article.</p> <p><a href="#table" data-linktype="self-bookmark">Back to table</a></p> <h2 id="Literals"> Character literals</h2> <p>The following characters in a custom date and time format string are reserved and are always interpreted as formatting characters or, in the case of <code>"</code>, <code>'</code>, <code>/</code>, and <code>\</code>, as special characters.</p> <ul> <li><code>F</code></li> <li><code>H</code></li> <li><code>K</code></li> <li><code>M</code></li> <li><code>d</code></li> <li><code>f</code></li> <li><code>g</code></li> <li><code>h</code></li> <li><code>m</code></li> <li><code>s</code></li> <li><code>t</code></li> <li><code>y</code></li> <li><code>z</code></li> <li><code>%</code></li> <li><code>:</code></li> <li><code>/</code></li> <li><code>"</code></li> <li><code>'</code></li> <li><code>\</code></li> </ul> <p>All other characters are always interpreted as character literals and, in a formatting operation, are included in the result string unchanged. In a parsing operation, they must match the characters in the input string exactly; the comparison is case-sensitive.</p> <p>The following example includes the literal characters "PST" (for Pacific Standard Time) and "PDT" (for Pacific Daylight Time) to represent the local time zone in a format string. Note that the string is included in the result string, and that a string that includes the local time zone string also parses successfully.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#20">using System; using System.Globalization; public class Example5 { public static void Main() { String[] formats = { "dd MMM yyyy hh:mm tt PST", "dd MMM yyyy hh:mm tt PDT" }; var dat = new DateTime(2016, 8, 18, 16, 50, 0); // Display the result string. Console.WriteLine(dat.ToString(formats[1])); // Parse a string. String value = "25 Dec 2016 12:00 pm PST"; DateTime newDate; if (DateTime.TryParseExact(value, formats, null, DateTimeStyles.None, out newDate)) Console.WriteLine(newDate); else Console.WriteLine("Unable to parse '{0}'", value); } } // The example displays the following output: // 18 Aug 2016 04:50 PM PDT // 12/25/2016 12:00:00 PM </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#20">Imports System.Globalization Module Example Public Sub Main() Dim formats() As String = {"dd MMM yyyy hh:mm tt PST", "dd MMM yyyy hh:mm tt PDT"} Dim dat As New Date(2016, 8, 18, 16, 50, 0) ' Display the result string. Console.WriteLine(dat.ToString(formats(1))) ' Parse a string. Dim value As String = "25 Dec 2016 12:00 pm PST" Dim newDate As Date If Date.TryParseExact(value, formats, Nothing, DateTimeStyles.None, newDate) Then Console.WriteLine(newDate) Else Console.WriteLine("Unable to parse '{0}'", value) End If End Sub End Module ' The example displays the following output: ' 18 Aug 2016 04:50 PM PDT ' 12/25/2016 12:00:00 PM </code></pre> <p>There are two ways to indicate that characters are to be interpreted as literal characters and not as reserve characters, so that they can be included in a result string or successfully parsed in an input string:</p> <ul> <li>By escaping each reserved character. For more information, see <a href="#escape" data-linktype="self-bookmark">Using the Escape Character</a>.</li> </ul> <p>The following example includes the literal characters "pst" (for Pacific Standard time) to represent the local time zone in a format string. Because both "s" and "t" are custom format strings, both characters must be escaped to be interpreted as character literals.</p> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#21">using System; using System.Globalization; public class Example3 { public static void Main() { String format = "dd MMM yyyy hh:mm tt p\\s\\t"; var dat = new DateTime(2016, 8, 18, 16, 50, 0); // Display the result string. Console.WriteLine(dat.ToString(format)); // Parse a string. String value = "25 Dec 2016 12:00 pm pst"; DateTime newDate; if (DateTime.TryParseExact(value, format, null, DateTimeStyles.None, out newDate)) Console.WriteLine(newDate); else Console.WriteLine("Unable to parse '{0}'", value); } } // The example displays the following output: // 18 Aug 2016 04:50 PM pst // 12/25/2016 12:00:00 PM </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#21">Imports System.Globalization Module Example Public Sub Main() Dim fmt As String = "dd MMM yyyy hh:mm tt p\s\t" Dim dat As New Date(2016, 8, 18, 16, 50, 0) ' Display the result string. Console.WriteLine(dat.ToString(fmt)) ' Parse a string. Dim value As String = "25 Dec 2016 12:00 pm pst" Dim newDate As Date If Date.TryParseExact(value, fmt, Nothing, DateTimeStyles.None, newDate) Then Console.WriteLine(newDate) Else Console.WriteLine("Unable to parse '{0}'", value) End If End Sub End Module ' The example displays the following output: ' 18 Aug 2016 04:50 PM pst ' 12/25/2016 12:00:00 PM </code></pre> <ul> <li>By enclosing the entire literal string in quotation marks or apostrophes. The following example is like the previous one, except that "pst" is enclosed in quotation marks to indicate that the entire delimited string should be interpreted as character literals.</li> </ul> <pre><code class="lang-csharp" name="Formatting.DateAndTime.Custom#22">using System; using System.Globalization; public class Example6 { public static void Main() { String format = "dd MMM yyyy hh:mm tt \"pst\""; var dat = new DateTime(2016, 8, 18, 16, 50, 0); // Display the result string. Console.WriteLine(dat.ToString(format)); // Parse a string. String value = "25 Dec 2016 12:00 pm pst"; DateTime newDate; if (DateTime.TryParseExact(value, format, null, DateTimeStyles.None, out newDate)) Console.WriteLine(newDate); else Console.WriteLine("Unable to parse '{0}'", value); } } // The example displays the following output: // 18 Aug 2016 04:50 PM pst // 12/25/2016 12:00:00 PM </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#22">Imports System.Globalization Module Example Public Sub Main() Dim fmt As String = "dd MMM yyyy hh:mm tt ""pst""" Dim dat As New Date(2016, 8, 18, 16, 50, 0) ' Display the result string. Console.WriteLine(dat.ToString(fmt)) ' Parse a string. Dim value As String = "25 Dec 2016 12:00 pm pst" Dim newDate As Date If Date.TryParseExact(value, fmt, Nothing, DateTimeStyles.None, newDate) Then Console.WriteLine(newDate) Else Console.WriteLine("Unable to parse '{0}'", value) End If End Sub End Module ' The example displays the following output: ' 18 Aug 2016 04:50 PM pst ' 12/25/2016 12:00:00 PM </code></pre><h2 id="notes">Notes</h2> <h3 id="UsingSingleSpecifiers"> Using single custom format specifiers</h3> <p>A custom date and time format string consists of two or more characters. Date and time formatting methods interpret any single-character string as a standard date and time format string. If they don't recognize the character as a valid format specifier, they throw a <a href="/en-us/dotnet/api/system.formatexception" class="no-loc" data-linktype="absolute-path">FormatException</a>. For example, a format string that consists only of the specifier "h" is interpreted as a standard date and time format string. However, in this particular case, an exception is thrown because there is no "h" standard date and time format specifier.</p> <p>To use any of the custom date and time format specifiers as the only specifier in a format string (that is, to use the "d", "f", "F", "g", "h", "H", "K", "m", "M", "s", "t", "y", "z", ":", or "/" custom format specifier by itself), include a space before or after the specifier, or include a percent ("%") format specifier before the single custom date and time specifier.</p> <p>For example, "<code>%h"</code> is interpreted as a custom date and time format string that displays the hour represented by the current date and time value. You can also use the " h" or "h " format string, although this includes a space in the result string along with the hour. The following example illustrates these three format strings.</p> <pre><code class="lang-csharp" data-interactive="csharp" name="Formatting.DateAndTime.Custom#16">DateTime dat1 = new DateTime(2009, 6, 15, 13, 45, 0); Console.WriteLine("'{0:%h}'", dat1); Console.WriteLine("'{0: h}'", dat1); Console.WriteLine("'{0:h }'", dat1); // The example displays the following output: // '1' // ' 1' // '1 ' </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#16">Dim dat1 As Date = #6/15/2009 1:45PM# Console.WriteLine("'{0:%h}'", dat1) Console.WriteLine("'{0: h}'", dat1) Console.WriteLine("'{0:h }'", dat1) ' The example displays the following output: ' '1' ' ' 1' ' '1 ' </code></pre><h4 id="escape"> Using the Escape character</h4> <p>The "d", "f", "F", "g", "h", "H", "K", "m", "M", "s", "t", "y", "z", ":", or "/" characters in a format string are interpreted as custom format specifiers rather than as literal characters. To prevent a character from being interpreted as a format specifier, you can precede it with a backslash (\), which is the escape character. The escape character signifies that the following character is a character literal that should be included in the result string unchanged.</p> <p>To include a backslash in a result string, you must escape it with another backslash (<code>\\</code>).</p> <div class="NOTE"> <p>Note</p> <p>Some compilers, such as the C++ and C# compilers, may also interpret a single backslash character as an escape character. To ensure that a string is interpreted correctly when formatting, you can use the verbatim string literal character (the @ character) before the string in C#, or add another backslash character before each backslash in C# and C++. The following C# example illustrates both approaches.</p> </div> <p>The following example uses the escape character to prevent the formatting operation from interpreting the "h" and "m" characters as format specifiers.</p> <pre><code class="lang-csharp" data-interactive="csharp" name="Formatting.DateAndTime.Custom#15">DateTime date = new DateTime(2009, 06, 15, 13, 45, 30, 90); string fmt1 = "h \\h m \\m"; string fmt2 = @"h \h m \m"; Console.WriteLine("{0} ({1}) -&gt; {2}", date, fmt1, date.ToString(fmt1)); Console.WriteLine("{0} ({1}) -&gt; {2}", date, fmt2, date.ToString(fmt2)); // The example displays the following output: // 6/15/2009 1:45:30 PM (h \h m \m) -&gt; 1 h 45 m // 6/15/2009 1:45:30 PM (h \h m \m) -&gt; 1 h 45 m </code></pre><pre><code class="lang-vb" name="Formatting.DateAndTime.Custom#15">Dim date1 As Date = #6/15/2009 13:45# Dim fmt As String = "h \h m \m" Console.WriteLine("{0} ({1}) -&gt; {2}", date1, fmt, date1.ToString(fmt)) ' The example displays the following output: ' 6/15/2009 1:45:00 PM (h \h m \m) -&gt; 1 h 45 m </code></pre><h3 id="control-panel-settings">Control Panel settings</h3> <p>The <strong>Regional and Language Options</strong> settings in Control Panel influence the result string produced by a formatting operation that includes many of the custom date and time format specifiers. These settings are used to initialize the <a href="/en-us/dotnet/api/system.globalization.datetimeformatinfo" class="no-loc" data-linktype="absolute-path">DateTimeFormatInfo</a> object associated with the current culture, which provides values used to govern formatting. Computers that use different settings generate different result strings.</p> <p>In addition, if you use the <a href="/en-us/dotnet/api/system.globalization.cultureinfo.-ctor#system-globalization-cultureinfo-ctor(system-string)" class="no-loc" data-linktype="absolute-path">CultureInfo(String)</a> constructor to instantiate a new <a href="/en-us/dotnet/api/system.globalization.cultureinfo" class="no-loc" data-linktype="absolute-path">CultureInfo</a> object that represents the same culture as the current system culture, any customizations established by the <strong>Regional and Language Options</strong> item in Control Panel will be applied to the new <a href="/en-us/dotnet/api/system.globalization.cultureinfo" class="no-loc" data-linktype="absolute-path">CultureInfo</a> object. You can use the <a href="/en-us/dotnet/api/system.globalization.cultureinfo.-ctor#system-globalization-cultureinfo-ctor(system-string-system-boolean)" class="no-loc" data-linktype="absolute-path">CultureInfo(String, Boolean)</a> constructor to create a <a href="/en-us/dotnet/api/system.globalization.cultureinfo" class="no-loc" data-linktype="absolute-path">CultureInfo</a> object that doesn't reflect a system's customizations.</p> <h3 id="datetimeformatinfo-properties">DateTimeFormatInfo properties</h3> <p>Formatting is influenced by properties of the current <a href="/en-us/dotnet/api/system.globalization.datetimeformatinfo" class="no-loc" data-linktype="absolute-path">DateTimeFormatInfo</a> object, which is provided implicitly by the current culture or explicitly by the <a href="/en-us/dotnet/api/system.iformatprovider" class="no-loc" data-linktype="absolute-path">IFormatProvider</a> parameter of the method that invokes formatting. For the <a href="/en-us/dotnet/api/system.iformatprovider" class="no-loc" data-linktype="absolute-path">IFormatProvider</a> parameter, you should specify a <a href="/en-us/dotnet/api/system.globalization.cultureinfo" class="no-loc" data-linktype="absolute-path">CultureInfo</a> object, which represents a culture, or a <a href="/en-us/dotnet/api/system.globalization.datetimeformatinfo" class="no-loc" data-linktype="absolute-path">DateTimeFormatInfo</a> object.</p> <p>The result string produced by many of the custom date and time format specifiers also depends on properties of the current <a href="/en-us/dotnet/api/system.globalization.datetimeformatinfo" class="no-loc" data-linktype="absolute-path">DateTimeFormatInfo</a> object. Your application can change the result produced by some custom date and time format specifiers by changing the corresponding <a href="/en-us/dotnet/api/system.globalization.datetimeformatinfo" class="no-loc" data-linktype="absolute-path">DateTimeFormatInfo</a> property. For example, the "ddd" format specifier adds an abbreviated weekday name found in the <a href="/en-us/dotnet/api/system.globalization.datetimeformatinfo.abbreviateddaynames" class="no-loc" data-linktype="absolute-path">AbbreviatedDayNames</a> string array to the result string. Similarly, the "MMMM" format specifier adds a full month name found in the <a href="/en-us/dotnet/api/system.globalization.datetimeformatinfo.monthnames" class="no-loc" data-linktype="absolute-path">MonthNames</a> string array to the result string.</p> <h2 id="see-also">See also</h2> <ul> <li><a href="/en-us/dotnet/api/system.datetime" class="no-loc" data-linktype="absolute-path">System.DateTime</a></li> <li><a href="/en-us/dotnet/api/system.iformatprovider" class="no-loc" data-linktype="absolute-path">System.IFormatProvider</a></li> <li><a href="formatting-types" data-linktype="relative-path">Formatting types</a></li> <li><a href="standard-date-and-time-format-strings" data-linktype="relative-path">Standard Date and Time format strings</a></li> <li><a href="/en-us/samples/dotnet/samples/windowsforms-formatting-utility-cs" data-linktype="absolute-path">Sample: .NET Core WinForms formatting utility (C#)</a></li> <li><a href="/en-us/samples/dotnet/samples/windowsforms-formatting-utility-vb" data-linktype="absolute-path">Sample: .NET Core WinForms formatting utility (Visual Basic)</a></li> </ul> </div><div id="ms--inline-notifications" class="margin-block-xs" data-bi-name="inline-notification"></div><div id="assertive-live-region" role="alert" aria-live="assertive" class="visually-hidden" aria-relevant="additions" aria-atomic="true"></div> <div id="polite-live-region" role="status" aria-live="polite" class="visually-hidden" aria-relevant="additions" aria-atomic="true"></div> <!-- </content> --> </main><!-- recommendations section --><!-- end recommendations section --> <!-- feedback section --><section class="feedback-section position-relative margin-top-lg border border-radius padding-xxs" data-bi-name="open-source-feedback-section" data-open-source-feedback-section hidden> <div class="display-flex flex-direction-column flex-direction-row-tablet"> <div class="width-450-tablet padding-inline-xs padding-inline-xs-tablet padding-top-xs padding-bottom-sm padding-top-xs-tablet background-color-body-medium"> <div class="display-flex flex-direction-column"> <div class="padding-bottom-xxs"> <span class="icon margin-right-xxs" aria-hidden="true"> <span class="docon docon-brand-github"></span> </span> <span class="font-weight-semibold" >Collaborate with us on GitHub</span> </div> <span class="line-height-normal"> The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see <a href="https://learn.microsoft.com/contribute/content/dotnet/dotnet-contribute">our contributor guide</a>. </span> </div> </div> <div class="display-flex gap-xs width-full-tablet flex-direction-column padding-xs justify-content-space-evenly"> <div class="media"><div class="media-left"> <div class="image image-36x36" hidden data-open-source-image-container> <img class="theme-display is-light" src="https://learn.microsoft.com/media/logos/logo_net.svg" aria-hidden="true" data-open-source-image-light/> <img class="theme-display is-dark is-high-contrast" src="https://learn.microsoft.com/media/logos/logo_net.svg" aria-hidden="true" data-open-source-image-dark/> </div> </div> <div class="media-content"> <p class="font-size-xl font-weight-semibold margin-bottom-xxs" data-open-source-product-title>.NET</p> <div class="display-flex gap-xs flex-direction-column"> <p class="line-height-normal" data-open-source-product-description></p> <div class="display-flex gap-xs flex-direction-column"> <a href="" data-github-link> <span class="icon margin-right-xxs" aria-hidden="true"> <span class="docon docon-bug"></span> </span> <span>Open a documentation issue</span> </a> <a href="https://aka.ms/feedback/report?space=61" class="display-block margin-top-auto font-size-md" data-feedback-product-url> <span class="icon margin-right-xxs" aria-hidden="true"> <span class="docon docon-feedback"></span> </span> <span>Provide product feedback</span> </a> </div> </div> </div> </div> </div> </div> </section><!-- end feedback section --> <!-- feedback report section --><!-- end feedback report section --><aside id="ms--additional-resources-mobile" aria-label="Additional resources" class="display-none-desktop display-none-print" > <hr class="hr" hidden /> <h2 id="ms--additional-resources-mobile-heading" class="title is-3" hidden>Additional resources</h2> <section id="right-rail-recommendations-mobile" data-bi-name="recommendations" hidden></section> <section id="right-rail-training-mobile" data-bi-name="learning-resources-card" hidden></section> <section id="right-rail-events-mobile" data-bi-name="events-card" hidden></section> <section id="right-rail-qna-mobile" data-bi-name="qna-link-card" hidden></section> </aside><div class="border-top is-visible-interactive has-default-focus margin-top-sm "><footer id="footer-interactive" data-bi-name="footer" class="footer-layout"><div class="display-flex gap-xs flex-wrap-wrap is-full-height padding-right-lg-desktop"><a data-mscc-ic="false" class="locale-selector-link button button-sm button-clear flex-shrink-0" href="#" data-bi-name="select-locale"> <span class="icon" aria-hidden="true"> <span class="docon docon-world"></span> </span> <span class="local-selector-link-text"></span></a><div class="ccpa-privacy-link" data-ccpa-privacy-link hidden> <a href="https://aka.ms/yourcaliforniaprivacychoices" class="button button-sm button-clear flex-shrink-0" data-mscc-ic="false" data-bi-name="your-privacy-choices" > <svg role="img" aria-label="California Consumer Privacy Act (CCPA) Opt-Out Icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 14" xml:space="preserve" height="16" width="43" focusable="false" > <title>California Consumer Privacy Act (CCPA) Opt-Out Icon</title> <path d="M7.4 12.8h6.8l3.1-11.6H7.4C4.2 1.2 1.6 3.8 1.6 7s2.6 5.8 5.8 5.8z" style="fill-rule:evenodd;clip-rule:evenodd;fill:#fff"></path> <path d="M22.6 0H7.4c-3.9 0-7 3.1-7 7s3.1 7 7 7h15.2c3.9 0 7-3.1 7-7s-3.2-7-7-7zm-21 7c0-3.2 2.6-5.8 5.8-5.8h9.9l-3.1 11.6H7.4c-3.2 0-5.8-2.6-5.8-5.8z" style="fill-rule:evenodd;clip-rule:evenodd;fill:#06f"></path> <path d="M24.6 4c.2.2.2.6 0 .8L22.5 7l2.2 2.2c.2.2.2.6 0 .8-.2.2-.6.2-.8 0l-2.2-2.2-2.2 2.2c-.2.2-.6.2-.8 0-.2-.2-.2-.6 0-.8L20.8 7l-2.2-2.2c-.2-.2-.2-.6 0-.8.2-.2.6-.2.8 0l2.2 2.2L23.8 4c.2-.2.6-.2.8 0z" style="fill:#fff"></path> <path d="M12.7 4.1c.2.2.3.6.1.8L8.6 9.8c-.1.1-.2.2-.3.2-.2.1-.5.1-.7-.1L5.4 7.7c-.2-.2-.2-.6 0-.8.2-.2.6-.2.8 0L8 8.6l3.8-4.5c.2-.2.6-.2.9 0z" style="fill:#06f"></path> </svg> <span>Your Privacy Choices</span> </a> </div> <div class="flex-shrink-0"> <div class="dropdown has-caret-up"> <button class="dropdown-trigger button button-clear button-sm has-inner-focus theme-dropdown-trigger" aria-controls="theme-menu-interactive" aria-expanded="false" title="Theme" data-bi-name="theme"> <span class="icon"> <span class="docon docon-sun" aria-hidden="true"></span> </span> <span>Theme</span> <span class="icon expanded-indicator" aria-hidden="true"> <span class="docon docon-chevron-down-light"></span> </span> </button> <div class="dropdown-menu" id="theme-menu-interactive" role="menu"> <ul class="theme-selector padding-xxs" role="none"> <li class="theme display-block" role="menuitem"> <button class="button button-clear button-sm theme-control button-block justify-content-flex-start" data-theme-to="light"> <span class="theme-light margin-right-xxs"> <span class="theme-selector-icon border display-inline-block has-body-background" aria-hidden="true"> <svg class="svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 14"> <rect width="22" height="14" class="has-fill-body-background" /> <rect x="5" y="5" width="12" height="4" class="has-fill-secondary" /> <rect x="5" y="2" width="2" height="1" class="has-fill-secondary" /> <rect x="8" y="2" width="2" height="1" class="has-fill-secondary" /> <rect x="11" y="2" width="3" height="1" class="has-fill-secondary" /> <rect x="1" y="1" width="2" height="2" class="has-fill-secondary" /> <rect x="5" y="10" width="7" height="2" rx="0.3" class="has-fill-primary" /> <rect x="19" y="1" width="2" height="2" rx="1" class="has-fill-secondary" /> </svg> </span> </span> <span>Light</span> </button> </li> <li class="theme display-block" role="menuitem"> <button class="button button-clear button-sm theme-control button-block justify-content-flex-start" data-theme-to="dark"> <span class="theme-dark margin-right-xxs"> <span class="border theme-selector-icon display-inline-block has-body-background" aria-hidden="true"> <svg class="svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 14"> <rect width="22" height="14" class="has-fill-body-background" /> <rect x="5" y="5" width="12" height="4" class="has-fill-secondary" /> <rect x="5" y="2" width="2" height="1" class="has-fill-secondary" /> <rect x="8" y="2" width="2" height="1" class="has-fill-secondary" /> <rect x="11" y="2" width="3" height="1" class="has-fill-secondary" /> <rect x="1" y="1" width="2" height="2" class="has-fill-secondary" /> <rect x="5" y="10" width="7" height="2" rx="0.3" class="has-fill-primary" /> <rect x="19" y="1" width="2" height="2" rx="1" class="has-fill-secondary" /> </svg> </span> </span> <span>Dark</span> </button> </li> <li class="theme display-block" role="menuitem"> <button class="button button-clear button-sm theme-control button-block justify-content-flex-start" data-theme-to="high-contrast"> <span class="theme-high-contrast margin-right-xxs"> <span class="border theme-selector-icon display-inline-block has-body-background" aria-hidden="true"> <svg class="svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 14"> <rect width="22" height="14" class="has-fill-body-background" /> <rect x="5" y="5" width="12" height="4" class="has-fill-secondary" /> <rect x="5" y="2" width="2" height="1" class="has-fill-secondary" /> <rect x="8" y="2" width="2" height="1" class="has-fill-secondary" /> <rect x="11" y="2" width="3" height="1" class="has-fill-secondary" /> <rect x="1" y="1" width="2" height="2" class="has-fill-secondary" /> <rect x="5" y="10" width="7" height="2" rx="0.3" class="has-fill-primary" /> <rect x="19" y="1" width="2" height="2" rx="1" class="has-fill-secondary" /> </svg> </span> </span> <span>High contrast</span> </button> </li> </ul> </div> </div> </div> </div> <ul class="links" data-bi-name="footerlinks"> <li class="manage-cookies-holder" hidden></li><li><a class="external-link-indicator" data-mscc-ic="false" href="/en-us/previous-versions/" data-bi-name="archivelink">Previous Versions</a></li> <li><a class="external-link-indicator" data-mscc-ic="false" href="https://techcommunity.microsoft.com/t5/microsoft-learn-blog/bg-p/MicrosoftLearnBlog" data-bi-name="bloglink">Blog</a></li> <li><a class="external-link-indicator" data-mscc-ic="false" href="/en-us/contribute/" data-bi-name="contributorGuide">Contribute</a></li><li><a class="external-link-indicator" data-mscc-ic="false" href="https://go.microsoft.com/fwlink/?LinkId=521839" data-bi-name="privacy">Privacy</a></li><li><a class="external-link-indicator" data-mscc-ic="false" href="/en-us/legal/termsofuse" data-bi-name="termsofuse">Terms of Use</a></li><li><a class="external-link-indicator" data-mscc-ic="false" href="https://www.microsoft.com/legal/intellectualproperty/Trademarks/" data-bi-name="trademarks">Trademarks</a></li><li>&copy; Microsoft 2024</li> </ul> </footer></div></div><div id="ms--additional-resources" class="right-container column is-4-desktop display-none display-block-desktop" data-bi-name="pageactions" role="complementary" aria-label="Additional resources" > <div id="affixed-right-container" class="margin-top-sm-tablet" data-bi-name="right-column"> <h2 id="ms--additional-resources-heading" class="title is-6 margin-top-md" hidden>Additional resources</h2> <section id="right-rail-events" data-bi-name="events-card" hidden></section> <section id="right-rail-training" data-bi-name="learning-resources-card" hidden></section> <section id="right-rail-recommendations" data-bi-name="recommendations" hidden></section> <nav id="side-doc-outline" class="doc-outline" data-bi-name="intopic toc" aria-label="In this article"> <h3>In this article</h3> </nav> <section id="right-rail-qna" class="margin-top-xxs" data-bi-name="qna-link-card" hidden></section> </div> </div></div> <!--end of div.columns --> </section> <!--end of .primary-holder --> <!-- interactive container --> <aside id="interactive-container" class="interactive-container is-visible-interactive column has-body-background-dark "> </aside> <!-- end of interactive container --> </div> </div> <!--end of .mainContainer --> <section class="border-top has-default-focus is-hidden-interactive margin-top-sm "><footer id="footer" data-bi-name="footer" class="footer-layout uhf-container has-padding" role="contentinfo"><div class="display-flex gap-xs flex-wrap-wrap is-full-height padding-right-lg-desktop"><a data-mscc-ic="false" class="locale-selector-link button button-sm button-clear flex-shrink-0" href="#" data-bi-name="select-locale"> <span class="icon" aria-hidden="true"> <span class="docon docon-world"></span> </span> <span class="local-selector-link-text"></span></a><div class="ccpa-privacy-link" data-ccpa-privacy-link hidden> <a href="https://aka.ms/yourcaliforniaprivacychoices" class="button button-sm button-clear flex-shrink-0" data-mscc-ic="false" data-bi-name="your-privacy-choices" > <svg role="img" aria-label="California Consumer Privacy Act (CCPA) Opt-Out Icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 14" xml:space="preserve" height="16" width="43" focusable="false" > <title>California Consumer Privacy Act (CCPA) Opt-Out Icon</title> <path d="M7.4 12.8h6.8l3.1-11.6H7.4C4.2 1.2 1.6 3.8 1.6 7s2.6 5.8 5.8 5.8z" style="fill-rule:evenodd;clip-rule:evenodd;fill:#fff"></path> <path d="M22.6 0H7.4c-3.9 0-7 3.1-7 7s3.1 7 7 7h15.2c3.9 0 7-3.1 7-7s-3.2-7-7-7zm-21 7c0-3.2 2.6-5.8 5.8-5.8h9.9l-3.1 11.6H7.4c-3.2 0-5.8-2.6-5.8-5.8z" style="fill-rule:evenodd;clip-rule:evenodd;fill:#06f"></path> <path d="M24.6 4c.2.2.2.6 0 .8L22.5 7l2.2 2.2c.2.2.2.6 0 .8-.2.2-.6.2-.8 0l-2.2-2.2-2.2 2.2c-.2.2-.6.2-.8 0-.2-.2-.2-.6 0-.8L20.8 7l-2.2-2.2c-.2-.2-.2-.6 0-.8.2-.2.6-.2.8 0l2.2 2.2L23.8 4c.2-.2.6-.2.8 0z" style="fill:#fff"></path> <path d="M12.7 4.1c.2.2.3.6.1.8L8.6 9.8c-.1.1-.2.2-.3.2-.2.1-.5.1-.7-.1L5.4 7.7c-.2-.2-.2-.6 0-.8.2-.2.6-.2.8 0L8 8.6l3.8-4.5c.2-.2.6-.2.9 0z" style="fill:#06f"></path> </svg> <span>Your Privacy Choices</span> </a> </div> <div class="flex-shrink-0"> <div class="dropdown has-caret-up"> <button class="dropdown-trigger button button-clear button-sm has-inner-focus theme-dropdown-trigger" aria-controls="theme-menu" aria-expanded="false" title="Theme" data-bi-name="theme"> <span class="icon"> <span class="docon docon-sun" aria-hidden="true"></span> </span> <span>Theme</span> <span class="icon expanded-indicator" aria-hidden="true"> <span class="docon docon-chevron-down-light"></span> </span> </button> <div class="dropdown-menu" id="theme-menu" role="menu"> <ul class="theme-selector padding-xxs" role="none"> <li class="theme display-block" role="menuitem"> <button class="button button-clear button-sm theme-control button-block justify-content-flex-start" data-theme-to="light"> <span class="theme-light margin-right-xxs"> <span class="theme-selector-icon border display-inline-block has-body-background" aria-hidden="true"> <svg class="svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 14"> <rect width="22" height="14" class="has-fill-body-background" /> <rect x="5" y="5" width="12" height="4" class="has-fill-secondary" /> <rect x="5" y="2" width="2" height="1" class="has-fill-secondary" /> <rect x="8" y="2" width="2" height="1" class="has-fill-secondary" /> <rect x="11" y="2" width="3" height="1" class="has-fill-secondary" /> <rect x="1" y="1" width="2" height="2" class="has-fill-secondary" /> <rect x="5" y="10" width="7" height="2" rx="0.3" class="has-fill-primary" /> <rect x="19" y="1" width="2" height="2" rx="1" class="has-fill-secondary" /> </svg> </span> </span> <span>Light</span> </button> </li> <li class="theme display-block" role="menuitem"> <button class="button button-clear button-sm theme-control button-block justify-content-flex-start" data-theme-to="dark"> <span class="theme-dark margin-right-xxs"> <span class="border theme-selector-icon display-inline-block has-body-background" aria-hidden="true"> <svg class="svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 14"> <rect width="22" height="14" class="has-fill-body-background" /> <rect x="5" y="5" width="12" height="4" class="has-fill-secondary" /> <rect x="5" y="2" width="2" height="1" class="has-fill-secondary" /> <rect x="8" y="2" width="2" height="1" class="has-fill-secondary" /> <rect x="11" y="2" width="3" height="1" class="has-fill-secondary" /> <rect x="1" y="1" width="2" height="2" class="has-fill-secondary" /> <rect x="5" y="10" width="7" height="2" rx="0.3" class="has-fill-primary" /> <rect x="19" y="1" width="2" height="2" rx="1" class="has-fill-secondary" /> </svg> </span> </span> <span>Dark</span> </button> </li> <li class="theme display-block" role="menuitem"> <button class="button button-clear button-sm theme-control button-block justify-content-flex-start" data-theme-to="high-contrast"> <span class="theme-high-contrast margin-right-xxs"> <span class="border theme-selector-icon display-inline-block has-body-background" aria-hidden="true"> <svg class="svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 14"> <rect width="22" height="14" class="has-fill-body-background" /> <rect x="5" y="5" width="12" height="4" class="has-fill-secondary" /> <rect x="5" y="2" width="2" height="1" class="has-fill-secondary" /> <rect x="8" y="2" width="2" height="1" class="has-fill-secondary" /> <rect x="11" y="2" width="3" height="1" class="has-fill-secondary" /> <rect x="1" y="1" width="2" height="2" class="has-fill-secondary" /> <rect x="5" y="10" width="7" height="2" rx="0.3" class="has-fill-primary" /> <rect x="19" y="1" width="2" height="2" rx="1" class="has-fill-secondary" /> </svg> </span> </span> <span>High contrast</span> </button> </li> </ul> </div> </div> </div> </div> <ul class="links" data-bi-name="footerlinks"> <li class="manage-cookies-holder" hidden></li><li><a class="external-link-indicator" data-mscc-ic="false" href="/en-us/previous-versions/" data-bi-name="archivelink">Previous Versions</a></li> <li><a class="external-link-indicator" data-mscc-ic="false" href="https://techcommunity.microsoft.com/t5/microsoft-learn-blog/bg-p/MicrosoftLearnBlog" data-bi-name="bloglink">Blog</a></li> <li><a class="external-link-indicator" data-mscc-ic="false" href="/en-us/contribute/" data-bi-name="contributorGuide">Contribute</a></li><li><a class="external-link-indicator" data-mscc-ic="false" href="https://go.microsoft.com/fwlink/?LinkId=521839" data-bi-name="privacy">Privacy</a></li><li><a class="external-link-indicator" data-mscc-ic="false" href="/en-us/legal/termsofuse" data-bi-name="termsofuse">Terms of Use</a></li><li><a class="external-link-indicator" data-mscc-ic="false" href="https://www.microsoft.com/legal/intellectualproperty/Trademarks/" data-bi-name="trademarks">Trademarks</a></li><li>&copy; Microsoft 2024</li> </ul> </footer> </section> <div id="action-panel" role="region" aria-label="Action Panel" class="action-panel has-default-focus" tabindex="-1"></div> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10