ConfigurationElement 中的 DateTime 属性

Big*_*air 5 c# datetime web-config configurationelement

我想将 DateTime 放入配置文件,但是,我希望 DateTime 以特定方式表示。我已经看到在 ConfigurationElement 中使用 DateTime 的示例(如下例所示)。我见过的例子都有以美国格式表示的日期。我想确保所有人都能理解日期,无论他们是谁,所以我想将其yyyy-MM-dd HH:mm:ss用作格式。

使用从 ConfigurationElement 派生的类时如何做到这一点?

    class MyConfigElement : ConfigurationElement
    {
        [ConfigurationProperty("Time", IsRequired=true)]
        public DateTime Time
        {
            get
            {
                return (DateTime)this["Time"];
            }
            set
            {
                this["Time"] = value;
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

Hen*_*man 3

你确定吗?Afaik,默认是 XML 样式,这也是您想要的 (yyyy-mm-dd)。