【发布时间】:2015-10-28 09:11:59
【问题描述】:
我有一个返回 Object 数组的方法。在Object 数组中,数据是日期时间。我需要将DateTime 数组转换为日期数组。 responseRows 返回 DateTime 数据。有没有办法可以将DateTime 转换为日期数组。
代码
public static object[] ExtractColumn(ResponseRow[] responseRows, int columnIndex)
{
if (columnIndex < 0)
{
return null;
}
return responseRows.Select(x => x.RowData[columnIndex]).ToArray();
}
【问题讨论】:
-
在 c# 中没有日期的数据类型。日期由
DateTime表示,时间为零 -
@wudzik 好的,但至少我可以将所有时间戳都转换为零
-
如果您返回
DateTime[],为什么还要返回object[]? -
@TimSchmelter 他没有将其转换为 DateTime,因此可能会出现编译时错误。
-
@Tim Schmelter 我的回复有时也可以是数字或字符串,在这里我将检查我的回复是否为日期时间,然后应用转换。