所以我想從.NET代碼轉換爲C# 下面的代碼:日期時間到C#
While getReader.Read
' getting the time in and time out 12 hour format
time_in = (getReader.Item("time_in").ToString)
time_out = (getReader.Item("time_out").ToString)
With Listview1.Items.Add(getReader.Item("worker_fullname").ToString)
.SubItems.Add(Format(time_in, "h:mm:ss tt"))
.SubItems.Add(Format(time_out, "h:mm:ss tt"))
.SubItems.Add(Format(getReader.Item("date"), "MMM dd, yyyy"))
End With
End While
在線代碼轉換不會幫我。我在(getReader.Item("time_in").ToString)
有困難。我試過DateTime.TryParseExact(getReader[3], "h:mm:ss tt", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out time_in);
,但它說它不能從對象轉換爲字符串。 而在End
和End With
中,似乎C#沒有用於此的等效語言結構。
你也應該顯示你的c#代碼。 – Rotem
溝「代碼轉換器」。你想讓你的C#代碼做*做什麼?你希望實現什麼功能?你寫了什麼代碼來實現該功能?它以何種方式無法按預期工作? – David
'time_in','time_out'字段的時間是多少?如果它是'DateTime'你不需要也不應該轉換或解析任何東西。只需將值轉換爲DateTime即可。這也應該在VB.NET代碼中完成。它實際上是一個*錯誤*使用字符串,而不是日期 –