2012-12-18 30 views
1

我正在使用的WinForms DataGridView, 我使用SQL Server數據庫 和我使用的SMALLDATETIME如數據類型,但它是接受的時間作爲mm/dd/yyyy HH:MM:ss AM如何保存在數據網格爲DD/MM/YYYY HH日期時間:毫米

如何保存在:
dd/mm/yyyy HH:MM AM格式 我感到有點困惑在這裏如何更改格式由設計師指定的DD/MM/YYYY格式不可

+3

你還在保存什麼數據庫? –

+0

我猜'DateTime'是DataGridView的數據類型,並且要控制日期的顯示格式,您應該將所需列的DefaultCellStyle,.Format設置爲MM/dd/yyyy HH:mm:ss' (Captial M爲幾個月,小M爲分鐘) – V4Vendetta

+0

尼爾我將它保存到SQL服務器 –

回答

2

使用下面的代碼:

DateTime.Now.ToString(CultureInfo.CreateSpecificCulture("en-AU")) 

利用文化信息,您可以設置不同的格式...

+0

我在哪裏寫這個代碼? –

+0

將項目鏈接到datagridview的位置。我不知道你的數據結構。這將是很好,如果你證明你還想顯示在datagridview – User1551892

+0

我只是想將smalldatetime的日期時間格式轉換爲指定的格式 –

1
DateTime currentDateTime = DateTime.Now;  // Use current time 
string format = "MMM ddd d HH:mm yyyy";  // Use this format 
string myDateTime = time.ToString(format)); // Write to console 

您可以製作任何格式,只需根據您的需要使用以下條件設置格式變量即可。

MMM  display three-letter month 
ddd  display three-letter day of the WEEK 
d  display day of the MONTH 
HH  display two-digit hours on 24-hour scale 
mm  display two-digit minutes 
yyyy display four-digit year 
M  display one-digit month number 
d  display one-digit day of the MONTH 
h  display one-digit hour on 12-hour scale 
mm  display two-digit minutes 
yy  display two-digit year 

更多示例和格式click here

相關問題