项目要求时间格式要统一,在web.config里能够自定义时间格式,
<add key="DateStringFormat" value="dd/MM/yyyy"/> 这里可以把格式改为任何.net系统里合法的格式,但是本地系统不一定支持。
日历用的是DateSelector_CSharp,从codeproject上下的, 地址是:
http://www.codeproject.com/aspnet/ASPNET_DateSelector.asp
在 该用户控件里获取项目定义的时间格式:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
这样textox里面是项目定义的时间格式了,
保存的时候就要用到DateTime.ParseExact
DateTime.ParseExact(AAA.CalendarDate,ModuleConfiguration.ModuleConfig.GetConfigValue("DateStringFormat"),DateTimeFormatInfo.InvariantInfo);
DateTimeFormatInfo.InvariantInfo为忽略本地系统时间格式。
ModuleConfiguration.ModuleConfig.GetConfigValue("DateStringFormat")为项目自定义时间格式。
AAA.CalendarDate为选择的时间。
在更新状态下:
从数据库里读出的时间也要用项目自定义格式格式化。
((DateTime)dt.Rows[0]["C_Date"]).ToString(ModuleConfiguration.ModuleConfig.GetConfigValue("DateStringFormat"), DateTimeFormatInfo.InvariantInfo);