Question

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?

Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top