I am using the following format to convert a DateTime to a string

setting.SettingValue = dt.ToString( "yyyy-MM-dd HH:mm:ss.fff" );

however the value is not as expected. The SettingValue property contains this value

2014-01-07 23.14.59.000

which uses a different time separator (.) instead of the specified one (:)

Any help?

有帮助吗?

解决方案

You haven't specified a format provider, so it's using the one from the current culture. If you always want to use :, you should specify an appropriate provider, e.g.:

setting.SettingValue = dt.ToString("yyyy-MM-dd HH:mm:ss.fff",
                                   CultureInfo.InvariantCulture);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top