统一项目时间格式(DateTime.ParseExact使用)
2007-05-24 15:15
316 查看
项目要求时间格式要统一,在web.config里能够自定义时间格式,
<add key="DateStringFormat" value="dd/MM/yyyy"/> 这里可以把格式改为任何.net系统里合法的格式,但是本地系统不一定支持。
日历用的是DateSelector_CSharp,从codeproject上下的, 地址是:
http://www.codeproject.com/aspnet/ASPNET_DateSelector.asp
string formatstr = ModuleConfiguration.ModuleConfig.GetConfigValue("DateStringFormat").ToLower();
string scriptStr = "javascript:return popUpCalendar(this," + getClientID() + @", '"+formatstr+@"', '__doPostBack(\'" + getClientID() + @"\')')";
//Response.Write(scriptStr);
imgCalendar.Attributes.Add("onclick", scriptStr);
注意:这里的时间格式放在js里面就要都改为小写形式,.net里面是dd/MM/yyyy,js里面就是dd/mm/yyyy。
这样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);
<add key="DateStringFormat" value="dd/MM/yyyy"/> 这里可以把格式改为任何.net系统里合法的格式,但是本地系统不一定支持。
日历用的是DateSelector_CSharp,从codeproject上下的, 地址是:
http://www.codeproject.com/aspnet/ASPNET_DateSelector.asp
string formatstr = ModuleConfiguration.ModuleConfig.GetConfigValue("DateStringFormat").ToLower();
string scriptStr = "javascript:return popUpCalendar(this," + getClientID() + @", '"+formatstr+@"', '__doPostBack(\'" + getClientID() + @"\')')";
//Response.Write(scriptStr);
imgCalendar.Attributes.Add("onclick", scriptStr);
注意:这里的时间格式放在js里面就要都改为小写形式,.net里面是dd/MM/yyyy,js里面就是dd/mm/yyyy。
这样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);
相关文章推荐
- DateTime.TryParseExact 万能时间格式转化
- C# DateTime的 ParseExact和 TryParseExact 使用说明
- 美国的时间格式 -- 复杂格式的日期转换 使用Date.parse(“复杂的格式”)方法。
- C#中用DateTime的ParseExact方法解析日期时间(excel中使用系统默认的日期格式)
- SilverLight项目里统一设置时间的格式兼容各种windows操作系统
- 基于DateTime.ParseExact方法的使用详解
- 关于DateTime在远程服务器使用以及日期与时间格式的问题
- C# DateTime显示时间格式的使用
- 如何把使用Navicat把Excel表格中时间日期以**dateTime**格式导入**MySQL**数据库
- C# 使用DateTime.TryParseExact将自定义日期类型转换成日期
- DateTime.ParseExact的使用
- 4000 oracle 使用datetime字段比较相等: to_timestemp()使用,把时间转为带毫秒级的格式
- MySQL时间字段究竟使用INT还是DateTime
- 使用作业,每天定时将DB中信息导出到指定的文件夹中txt文本中(文件格式按照时间)
- 使用VS2010的Database 项目模板统一管理数据库对象
- strftime和strptime使用(时间日期的格式控制函数)
- 根据时间查询,时间需要统一格式
- C#关于DateTime得到的当前时间的格式问题
- SpringMVC使用@ResponseBody时返回json的日期格式、@DatetimeFormat使用注意
- Mysql 设置datetime不能为当前时间,使用timestamp