我使用VB.NET 2008在Windows7上製作一個程序,該程序使用日期和日期時間選擇器,這很好用。VB.NET 2008,XP,DateTime類型
像這樣:
With dtp_date1
'here crashes
.Text = DateTime.Now.Date.ToString("dd.MM.yyyy.") & " 00:00:00"
.Format = DateTimePickerFormat.Custom
.CustomFormat = "dd.MM.yyyy. HH:mm:ss tt"
.ShowUpDown = False
End With
With dtp_date2
.Text = DateTime.Now.Date.ToString("dd.MM.yyyy.") & " 23:59:59.9999"
.Format = DateTimePickerFormat.Custom
.CustomFormat = "dd.MM.yyyy. HH:mm:ss tt"
.ShowUpDown = False
End With
該工程確定,直到我把這個程序到Windows XP。出現 錯誤:
string was not recognized as a valid Datetime
我嘗試這樣解決這個問題:
.Text = CDate(DateTimeNow.Date.ToString("dd.MM.yyyy.") & " 00:00:00").ToString
在這裏得到錯誤:
Conversion from string "06.01.2013. 00.00.00" to type 'Date' is not valid.
因爲我在計劃中有許多地方與日期怎樣做才能修復這個錯誤?
您只想在'string'中使用日期值設置'dtp_date2'嗎? – bonCodigo
您需要檢查XP盒默認的_culture_。這可能與其他機器中的不同。 – Oded
bonCodigo,我想設置dtp_date1和dtp_date2以及更多程序。 Oded,我應該在XP還是在win7中改變「文化」?怎麼做?我可以強制某些「文化」只是我的程序嗎? –