How to enable milliseconds in DateTime user settings?

I have the following user parameter 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> </userSettings> 

Is there any way to indicate that this parameter should be serialized with milliseconds - for example, 07/06/2010 13:05:10.181 - so that I can accurately compare it with the SQL Server datetime field?

+4
source share
2 answers

Unfortunately, you cannot save millisecond values ​​in settings. Deep in the System.Configuration.SettingsPropertyValue.ConvertObjectToString process, the DateTime value is converted to a string using the TypeConverter.ConvertToInvariantString method, which does not create milliseconds.

If you really need this level of accuracy, and you need to save it in user settings, you should use a different type of parameter, for example a string, using a custom format that includes milliseconds. None of the standard time formats include milliseconds.

+9
source

You can try saving it as Int64 , which would save the entire DateTime value without any formatting problems or loss of fidelity.

+1
source

Source: https://habr.com/ru/post/1314871/


All Articles