Skip to main content
 首页 » 编程设计

c#之将格式应用于 DataTable 中的列

2024年02月20日9haluo1

我有一个包含 DateTime 类型列的 .NET DataTable。我想使用“y”格式说明符将日期格式化为月、年。 我宁愿不必遍历所有更改值的行/列。 最好的方法是什么?

请您参考如下方法:

DataTable 只是存储值。它不提供格式化。在将 DateTime 放入 DataTable 之前格式化它(因此将其存储为字符串),或者对 DataTable 绑定(bind)到的控件进行格式化(例如,DataGridView 具有用于单元格样式的 Format 属性)。