1

DataGridView在 WinForms 中使用,我使用的是 sql server 数据库,我使用 smalldatetime 作为数据类型,但它接受的日期为mm/dd/yyyy HH:MM:ss AM.

如何将其保存为:
dd/mm/yyyy HH:MM AM格式我在这里有点困惑如何更改格式,因为设计师指定的 dd/mm/yyyy 格式不可用

4

2 回答 2

2

使用以下代码:

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

通过使用文化信息,您可以设置不同的格式...

于 2012-12-18T09:34:28.127 回答
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

有关更多示例和格式,请单击此处

于 2012-12-19T17:51:52.997 回答