开发者

How to include milliseconds in a DateTime user setting?

I have the following user setting defined in app.config:

<userSettings>
    <MyProject.Properties.Settings>
        <setting name="LastProcessedDate" serializeAs="String">
            <value>07/06/2010 13:05:10</value>
        </setting>
    </MyProject.Properties.Settings>
&l开发者_JS百科t;/userSettings>

Is there a way to specify that this setting should be serialized with the milliseconds - e.g. 07/06/2010 13:05:10.181 - so that I can accurately compare it to a SQL Server datetime field?


Unfortunately, you can't save millisecond values in settings. Deep down in the System.Configuration.SettingsPropertyValue.ConvertObjectToString method the DateTime value is converted to a string using the TypeConverter.ConvertToInvariantString method which doesn't produce milliseconds.

If you really want that level of accuracy and you must save it in the user settings, you should use a different parameter type like string using a custom format that includes milliseconds. None of the standard time formats includes milliseconds.


You could try storing it as an Int64, which would preserve the entire value of the DateTime without any formatting issues or loss of fidelity.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜