答案 0 :(得分:0)
您应该使用此示例(示例):
static void Main()
{
DateTime time = DateTime.Now; // Use current time.
string format = "yyyy/MM/dd hh:mm:ss"; // Use this format.
Console.WriteLine(time.ToString(format)); // Write to console.
}
因此,当将数据插入GridView时,会将其转换为具有选定格式的字符串。
以下是多种日期格式以及如何使用它们的链接:https://www.dotnetperls.com/datetime-format
答案 1 :(得分:0)
与我的复杂程序中孤立的工作代码相比,回答我的问题要容易得多。因此,这是我的程序中可以使用的技巧:
private void GridView_CustomDrawEvent(object sender, RowCellCustomDrawEventArgs e)
{
if(e.Column.FieldName == "CreationDate")
{
string date = ((DateTime) view.GetRowCellValue(e.RowHandle, "CreationDate"));
string displayDate = date.ToShortDateString() + " " time.ToLongTimeString();
e.DisplayText = displayDate;
}
}
我在DateTime事件中捕获了CustomDrawCell对象,并使用两种标准方法DateTime.ToShortDateString()和DateTime.ToLongTimeString().将其转换为字符串,非常感谢。
答案 2 :(得分:0)