2017-04-20 41 views
-2

如何將字符串「2016年11月17日星期四15:33:56」更改爲mm/dd/yyyy日期格式。我已經嘗試使用內置的VB.NET日期函數CDate()如何將字符串轉換爲mm/dd/yyyy格式

+1

一派 「vb.net日期的TryParse」 和第一個結果https://msdn.microsoft.com/de-de/library/ch92fbc1(v=vs.110).aspx – muffi

+2

請參見[問]並參加[遊覽]。這是值得展示你的代碼。 – Bugs

+0

@muffi - 基於這個問題,我懷疑OP知道尋找術語「TryParse」,但我同意一個簡單的搜索應該先試過。 –

回答

1

下面是一些適用於您給出的日期作爲示例的代碼。

Dim str As String = "15:33:56 Thursday 17th, November 2016" 

'Remove the "th" from "17th, since this confuses the parser 
str = System.Text.RegularExpressions.Regex.Replace(str, "[a-z]{2}(?=,)", String.Empty) 

'change the date to mm/dd/yyyy format 
str = DateTime.Parse(str).ToString("MM/dd/yyyy") 
+0

非常感謝你@ben j完美地工作 – Muroiwa263

相關問題