以文本方式查看主题 - Foxtable(狐表) (http://www.foxtable.com/bbs/index.asp) -- 专家坐堂 (http://www.foxtable.com/bbs/list.asp?boardid=2) ---- [分享]再谈系统日期格式冲突 (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=93429) |
-- 作者:wyz20130512 -- 发布时间:2016/11/28 21:45:00 -- [分享]再谈系统日期格式冲突 晚上看以前的Foxtable笔记时,发现以前学习时,已记录了一个如何修正系统日期的方法,代码更简捷: \'代码写入项目BeforeOpenProject事件中 Dim d As Date = Date.Today Dim s As String = CStr(d) Dim l As Integer = s.Length If l > 10 Then \'判断系统日期是否符合标准 Registry.SetValue("HKEY_CURRENT_USER\\Control Panel\\International","sShortDate","yyyy-MM-dd") e.Cancel = True e.HideSplashForm = True MessageBox.Show("程序将自动关闭,以校对系统日期格式!" & vbcrlf & "而后请重新启动程序","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning) Syscmd.Project.Exit() End If 比下面的:1.代码简捷;2.不用设置全局代码3.等效. |
-- 作者:有点蓝 -- 发布时间:2016/11/28 21:59:00 -- win10测试可以,长日期可以改为 Registry.SetValue("HKEY_CURRENT_USER\\Control Panel\\International","sLongDate","yyyy-MM-dd") |
-- 作者:wyz20130512 -- 发布时间:2016/11/28 22:45:00 -- 回复:(有点蓝)win10测试可以,长日期可以改为Regis... 感谢"有点蓝"大师的补充,这下就完美了.我是在Win7下测试通过的. |
-- 作者:逛逛 -- 发布时间:2016/11/29 8:08:00 -- 要是每个软件都来改一下,不是乱套了嘛? |
-- 作者:有点色 -- 发布时间:2016/11/29 8:58:00 -- 一个,是foxtable本身有问题,对于日期的处理,要考虑长日期的问题。
再一个,是,自己编写代码的时候,要考虑日期格式的问题。
当然,修改系统的日期格式,是最简单也是最粗暴的方式。 |
-- 作者:逛逛 -- 发布时间:2016/11/29 9:32:00 -- 这个和狐表应该没啥关系。 我只想建议,尽量别用直接修改系统时间的方法(别的程序也许对时间格式也会有要求) 而是通过DateTimeFormatInfo的CurrentInfo属性来控制 比如网上抄来的代码:AfterOpenProject Dim cd As System.Globalization.DateTimeFormatInfo = System.Globalization.DateTimeFormatInfo.CurrentInfo Dim DateInfo As System.Reflection.FieldInfo = cd.Gettype.GetField("generalLongTimePattern", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance) If DateInfo IsNot Nothing Then DateInfo.SetValue(cd, "yyyy-MM-dd HH:mm:ss") End If 或者一个个设 cd.ShortDatePattern = "yyyy年MM月dd日" |
-- 作者:有点蓝 -- 发布时间:2016/11/29 9:42:00 -- 同意楼上,能用代码解决的,就尽量不要动操作系统。6楼的方式更好 |
-- 作者:wyz20130512 -- 发布时间:2016/11/29 12:22:00 -- 回复:(逛逛)这个和狐表应该没啥关系。我只想建议,... 可我的BeforeLoadInnerTable事件设置了只加载指定日期的数据,若操作系统的日期格式不是标准格式,按你的代码还是报错! |
-- 作者:逛逛 -- 发布时间:2016/11/29 13:03:00 -- 定义一个变量,在出错的事件最上面,检查一下是否已经定义了时间格式,没有得话,定义一下就行了。 比如:BeforeLoadInnerTable 事件 定义一个变量Vars("ddd") = false If Vars("ddd") = False Then Dim cd As System.Globalization.DateTimeFormatInfo = System.Globalization.DateTimeFormatInfo.CurrentInfo Dim DateInfo As System.Reflection.FieldInfo = cd.Gettype.GetField("generalLongTimePattern", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance) If DateInfo IsNot Nothing Then DateInfo.SetValue(cd, "yyyy-MM-dd HH:mm:ss") End If Vars("ddd") = True End If 下面写你的代码 |
-- 作者:有点色 -- 发布时间:2016/11/29 13:47:00 -- mark |