1. <tfoot id='jqpeT'></tfoot>
  2. <small id='jqpeT'></small><noframes id='jqpeT'>

      <bdo id='jqpeT'></bdo><ul id='jqpeT'></ul>
    <legend id='jqpeT'><style id='jqpeT'><dir id='jqpeT'><q id='jqpeT'></q></dir></style></legend>

    <i id='jqpeT'><tr id='jqpeT'><dt id='jqpeT'><q id='jqpeT'><span id='jqpeT'><b id='jqpeT'><form id='jqpeT'><ins id='jqpeT'></ins><ul id='jqpeT'></ul><sub id='jqpeT'></sub></form><legend id='jqpeT'></legend><bdo id='jqpeT'><pre id='jqpeT'><center id='jqpeT'></center></pre></bdo></b><th id='jqpeT'></th></span></q></dt></tr></i><div id='jqpeT'><tfoot id='jqpeT'></tfoot><dl id='jqpeT'><fieldset id='jqpeT'></fieldset></dl></div>
    1. 设置默认日期时间格式 c#

      Set Default DateTime Format c#(设置默认日期时间格式 c#)
        <bdo id='h6jke'></bdo><ul id='h6jke'></ul>

          <tbody id='h6jke'></tbody>

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

                <legend id='h6jke'><style id='h6jke'><dir id='h6jke'><q id='h6jke'></q></dir></style></legend>
              • <tfoot id='h6jke'></tfoot>
              • <small id='h6jke'></small><noframes id='h6jke'>

              • 本文介绍了设置默认日期时间格式 c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                有没有办法为整个应用程序设置或覆盖默认的 DateTime 格式.我正在用 C# .Net MVC 1.0 编写一个应用程序,并使用了很多泛型和反射.如果我可以将默认的 DateTime.ToString() 格式覆盖为dd-MMM-yyyy",将会简单得多.当网站在不同的机器上运行时,我不希望这种格式发生变化.

                Is there a way of setting or overriding the default DateTime format for an entire application. I am writing an app in C# .Net MVC 1.0 and use alot of generics and reflection. Would be much simpler if I could override the default DateTime.ToString() format to be "dd-MMM-yyyy". I do not want this format to change when the site is run on a different machine.

                编辑 -只是为了澄清我的意思是专门调用 ToString,而不是其他扩展函数,这是因为反射/生成的代码.只更改 ToString 输出会更容易.

                Edit - Just to clarify I mean specifically calling the ToString, not some other extension function, this is because of the reflection / generated code. Would be easier to just change the ToString output.

                推荐答案

                日期时间的默认格式"是:

                The "default format" of a datetime is:

                ShortDatePattern + ' ' + LongTimePattern
                

                至少在当前 mono实施.如果您想显示类似 2001-02-03T04:05:06Z 的内容,即 ISO 8606,但在您的情况下不是大问题:

                at least in the current mono implementation. This is particularly painful in case you want to display something like 2001-02-03T04:05:06Z i.e. the date and time combined as specified in ISO 8606, but not a big problem in your case:

                using System;
                using System.Globalization;
                using System.Threading;
                
                namespace test {
                    public static class Program {
                        public static void Main() {
                            CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
                            culture.DateTimeFormat.ShortDatePattern = "dd-MMM-yyyy";
                            culture.DateTimeFormat.LongTimePattern = "";
                            Thread.CurrentThread.CurrentCulture = culture;
                            Console.WriteLine(DateTime.Now);
                        }
                    }
                }
                

                这将设置 ToString 在日期时间上的默认行为以返回您期望的格式.

                This will set the default behavior of ToString on datetimes to return the format you expect.

                这篇关于设置默认日期时间格式 c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                C# namespace alias - what#39;s the point?(C# 命名空间别名 - 有什么意义?)
                Using Xpath With Default Namespace in C#(在 C# 中使用具有默认命名空间的 Xpath)
                Generating an EDMX from a DB2 Database(从 DB2 数据库生成 EDMX)
                Datetime field overflow with IBM Data Server Client v9.7fp5(IBM Data Server Client v9.7fp5 的日期时间字段溢出)
                IBM .NET Data Provider Connection String issue with Library List(库列表的 IBM .NET 数据提供程序连接字符串问题)
                .NET DB2 OLEDB pre-requisites(.NET DB2 OLEDB 先决条件)

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

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

                3. <legend id='Ey0fR'><style id='Ey0fR'><dir id='Ey0fR'><q id='Ey0fR'></q></dir></style></legend>
                          <tbody id='Ey0fR'></tbody>

                          <bdo id='Ey0fR'></bdo><ul id='Ey0fR'></ul>
                        • <tfoot id='Ey0fR'></tfoot>