2012-05-24 120 views
2

我有一個字符串,其格式爲ddMMyyhhmmss。VB.NET轉換日期字符串ddMMyyhhmmss到日期對象

240512024707

我需要能夠在此日期轉換爲真正的.NET Date對象。

我目前正在使用CDate,但它似乎CDate無法識別的格式,有沒有任何方式指定字符串格式爲CDate?

row.Item("NoteDate") = CDate(n.noteText.Substring(0, 12).ToString).ToString("dd/MM/yyyy hh:mm:ss")

回答

7

您有日期的字符串,你知道確切的格式字符串 - 使用DateTime.ParseExact(或DateTime.TryParseExact如果你想避免潛在引發異常):

DateTime.ParseExact("240512024707", "ddMMyyhhmmss", CultureInfo.InvariantCulture) 
相關問題