我是C#.net中的Windows Forms桌面应用程序。我在SQL Server数据库的公历中保存了DateTime
。现在我想在DataGridView
列中以Shamsi(Jalali/Peersian)日历格式显示DateTime
。如何在DataGridView中显示Persian DateTime
如何在DataGridView
中显示波斯语DateTime
而数据库中的数据是格里高利DateTime
?
我是C#.net中的Windows Forms桌面应用程序。我在SQL Server数据库的公历中保存了DateTime
。现在我想在DataGridView
列中以Shamsi(Jalali/Peersian)日历格式显示DateTime
。如何在DataGridView中显示Persian DateTime
如何在DataGridView
中显示波斯语DateTime
而数据库中的数据是格里高利DateTime
?
您可以将列的默认格式更改为自定义格式。
例如,如果你列第3列:
dataGridView1.Columns[2].DefaultCellStyle.Format = "MM/dd/yyyy HH:mm:ss";
您更改任何你想要的格式。
DateTime dt = DateTime.Now;
// Sets the CurrentCulture property to U.S. English.
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
// Displays dt, formatted using the ShortDatePattern
// and the CurrentThread.CurrentCulture.
Console.WriteLine(dt.ToString("d"));
// Creates a CultureInfo for German in Germany.
CultureInfo ci = new CultureInfo("de-DE");
// Displays dt, formatted using the ShortDatePattern
// and the CultureInfo.
Console.WriteLine(dt.ToString("d", ci));
,你可以在你通过自己的文化我不知道你的文化代码是什么
您的解决方案不会在Win 7的工作!!!! – user6641321
@ user6641321你是什么意思? – eg16
我的意思是说,我在数据库中有一个日期时间字段,所以当我在datagridview中显示表的数据时,该字段是格雷戈里,但我想显示波斯日期。 – user6641321