<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“日";没有前导零

      Format .NET DateTime quot;Dayquot; with no leading zero(格式化 .NET DateTime“日;没有前导零)

          <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“日";没有前导零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Force JsonConvert.SerializeXmlNode to serialize node value as an Integer or a Boolean(强制 JsonConvert.SerializeXmlNode 将节点值序列化为整数或布尔值)
                Using JSON to Serialize/Deserialize TimeSpan(使用 JSON 序列化/反序列化 TimeSpan)
                Could not determine JSON object type for type quot;Classquot;(无法确定类型“Class的 JSON 对象类型.)
                How to deserialize a JSONP response (preferably with JsonTextReader and not a string)?(如何反序列化 JSONP 响应(最好使用 JsonTextReader 而不是字符串)?)
                how to de-serialize JSON data in which Timestamp it-self contains fields?(如何反序列化时间戳本身包含字段的JSON数据?)
                JSON.Net custom contract serialization and Collections(JSON.Net 自定义合约序列化和集合)

                    <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>
                        <tbody id='OaDBT'></tbody>

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

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