我在我的项目中使用了以下代码。使用此FxCop时,会出现CA1305警告。
string endtime = string.Format("{0:0000}{1:00}{2:00}T{3:00}{4:00}{5:00}", SchAppointment.EndTime.Year, SchAppointment.EndTime.Month, SchAppointment.EndTime.Day, SchAppointment.EndTime.TimeOfDay.Hours, SchAppointment.EndTime.TimeOfDay.Minutes, SchAppointment.EndTime.TimeOfDay.Seconds);
提前谢谢。
您的代码应该是这样的:
string endtime = string.Format( CultureInfo.CurrentCulture, "{0:0000}{1:00}{2:00}T{3:00}{4:00}{5:00}", SchAppointment.EndTime.Year, SchAppointment.EndTime.Month, SchAppointment.EndTime.Day, SchAppointment.EndTime.TimeOfDay.Hours, SchAppointment.EndTime.TimeOfDay.Minutes, SchAppointment.EndTime.TimeOfDay.Seconds);
这为格式化方法提供了格式化数字的信息。