我有以下代碼:如何從字符串'01/25/1955'獲取日期時間?
Dim dtDoM As Nullable(Of DateTime)
If (txtMarriageDate.Text.Trim = "") Then
dtDoM = Nothing
Else
dtDoM = DateTime.ParseExact(txtMarriageDate.Text.Trim + " 00:00:00", "dd/MM/yyyy hh:mm:ss", System.Globalization.CultureInfo.InvariantCulture)
'dtDoM = Convert.ToDateTime(txtMarriageDate.Text)
End If
在註釋掉部分我得到的出現FormatException「字符串未被識別爲日期時間」,並在新的代碼我收到「System.FormatException = {」日期時間代表在日曆中不支持該字符串System.Globalization.GregorianCalendar。「}」
編輯:已回答。我不能相信我忽略了這一點。
哦,我的。我討厭與其他人的代碼合作。簡直不敢相信我沒注意到。 – tsdexter 2012-04-17 17:26:38