以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  字符串转日期  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=72510)

--  作者:jhbhappy
--  发布时间:2015/7/31 10:33:00
--  字符串转日期
请问各位老师,表格中的订单编号20150730-001如何转成日期 2015-07-30
--  作者:sloyy
--  发布时间:2015/7/31 10:52:00
--  
Dim str As String = "20150730-001"
Dim d As Date = str.Insert(4,"-").Insert(7,"-")

--  作者:有点蓝
--  发布时间:2015/7/31 10:54:00
--  
也可以这样
Dim s As String = "20150730-001"
Dim s1 As String = Mid(s,1,4) & "-" & Mid(s,5,2) & "-" & Mid(s,7,2)
Output.Show(CDate(s1))

--  作者:jhbhappy
--  发布时间:2015/7/31 13:12:00
--  
谢了,试试
--  作者:恒隆君
--  发布时间:2018/4/6 16:31:00
--  
从字符串转换至日期,
报错

Dim str As String = "20170506"
Dim d As Date = str.Insert(4,"-").Insert(7,"-")
    e.datarow("生产日期") = cdate(d)

.NET Framework 版本:2.0.50727.8766
Foxtable 版本:2018.3.9.1
错误所在事件:表,原色墨信息,DataColChanged
详细错误信息:
Exception has been thrown by the target of an invocation.
从字符串“2017-05-06\'”到类型“Date”的转换无效。


--  作者:有点甜
--  发布时间:2018/4/6 16:35:00
--  
以下是引用恒隆君在2018/4/6 16:31:00的发言:
 
Exception has been thrown by the target of an invocation.
从字符串“2017-05-06\'”到类型“Date”的转换无效。

 

afterOpenProject事件,短日期

 

Dim cd As System.Globalization.DateTimeFormatInfo = System.Globalization.DateTimeFormatInfo.CurrentInfo
cd.ShortDatePattern = "yyyy年MM月dd日"
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