<small id='nfccn'></small><noframes id='nfccn'>

  1. <tfoot id='nfccn'></tfoot>

  2. <legend id='nfccn'><style id='nfccn'><dir id='nfccn'><q id='nfccn'></q></dir></style></legend>
      <bdo id='nfccn'></bdo><ul id='nfccn'></ul>

    1. <i id='nfccn'><tr id='nfccn'><dt id='nfccn'><q id='nfccn'><span id='nfccn'><b id='nfccn'><form id='nfccn'><ins id='nfccn'></ins><ul id='nfccn'></ul><sub id='nfccn'></sub></form><legend id='nfccn'></legend><bdo id='nfccn'><pre id='nfccn'><center id='nfccn'></center></pre></bdo></b><th id='nfccn'></th></span></q></dt></tr></i><div id='nfccn'><tfoot id='nfccn'></tfoot><dl id='nfccn'><fieldset id='nfccn'></fieldset></dl></div>

      格式化 .NET DateTime“日";没有前导零

      时间:2023-05-20

          <tbody id='z9U5L'></tbody>
          <tfoot id='z9U5L'></tfoot>
          <legend id='z9U5L'><style id='z9U5L'><dir id='z9U5L'><q id='z9U5L'></q></dir></style></legend>
          1. <i id='z9U5L'><tr id='z9U5L'><dt id='z9U5L'><q id='z9U5L'><span id='z9U5L'><b id='z9U5L'><form id='z9U5L'><ins id='z9U5L'></ins><ul id='z9U5L'></ul><sub id='z9U5L'></sub></form><legend id='z9U5L'></legend><bdo id='z9U5L'><pre id='z9U5L'><center id='z9U5L'></center></pre></bdo></b><th id='z9U5L'></th></span></q></dt></tr></i><div id='z9U5L'><tfoot id='z9U5L'></tfoot><dl id='z9U5L'><fieldset id='z9U5L'></fieldset></dl></div>
            • <small id='z9U5L'></small><noframes id='z9U5L'>

              • <bdo id='z9U5L'></bdo><ul id='z9U5L'></ul>
                本文介绍了格式化 .NET DateTime“日";没有前导零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                对于以下代码,我希望 result 等于 2,因为 MSDN 声明d"将月份中的日期表示为从 1 到 31 的数字.一位数day 的格式没有前导零.".

                For the following code, I would expect result to equal 2, because the MSDN states that 'd' "Represents the day of the month as a number from 1 through 31. A single-digit day is formatted without a leading zero.".

                DateTime myDate = new DateTime( 2009, 6, 4 );
                string result = myDate.ToString( "d" );
                

                但是,result 实际上等于 '6/4/2009' - 这是短日期格式(也是 'd').我可以使用dd",但这会添加一个前导零,这是我不想要的.

                However, result is actually equal to '6/4/2009' - which is the short-date format (which is also 'd'). I could use 'dd', but that adds a leading zero, which I don't want.

                推荐答案

                要表明这是一个自定义格式说明符(与标准格式说明符相反),它必须是两个字符长.这可以通过添加空格(将显示在输出中)或在单个字母前添加百分号来实现,如下所示:

                To indicate that this is a custom format specifier (in contrast to a standard format specifier), it must be two characters long. This can be accomplished by adding a space (which will show up in the output), or by including a percent sign before the single letter, like this:

                string result = myDate.ToString("%d");
                

                请参阅 文档

                这篇关于格式化 .NET DateTime“日";没有前导零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:使用任意字符串向左或向右填充 string.format(不是 padleft 或 padright) 下一篇:在 Console.WriteLine 方法中格式化字符串

                相关文章

                  <legend id='OaDBT'><style id='OaDBT'><dir id='OaDBT'><q id='OaDBT'></q></dir></style></legend>
                  • <bdo id='OaDBT'></bdo><ul id='OaDBT'></ul>
                  <i id='OaDBT'><tr id='OaDBT'><dt id='OaDBT'><q id='OaDBT'><span id='OaDBT'><b id='OaDBT'><form id='OaDBT'><ins id='OaDBT'></ins><ul id='OaDBT'></ul><sub id='OaDBT'></sub></form><legend id='OaDBT'></legend><bdo id='OaDBT'><pre id='OaDBT'><center id='OaDBT'></center></pre></bdo></b><th id='OaDBT'></th></span></q></dt></tr></i><div id='OaDBT'><tfoot id='OaDBT'></tfoot><dl id='OaDBT'><fieldset id='OaDBT'></fieldset></dl></div>

                  1. <small id='OaDBT'></small><noframes id='OaDBT'>

                    <tfoot id='OaDBT'></tfoot>