[英]DateTime.ToString() format error
I am using the following format to convert a DateTime to a string 我正在使用以下格式将DateTime转换为字符串
setting.SettingValue = dt.ToString( "yyyy-MM-dd HH:mm:ss.fff" );
however the value is not as expected. 但是,该值不符合预期。 The
SettingValue
property contains this value SettingValue
属性包含此值
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, eg: 如果始终要使用
:
,则应指定适当的提供程序,例如:
setting.SettingValue = dt.ToString("yyyy-MM-dd HH:mm:ss.fff",
CultureInfo.InvariantCulture);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.