Oracle将ISO日期转换为计算机区域设置日期/时间

时间:2010-12-11 01:18:06

标签: c# oracle

我使用以下插入字符串插入Oracle数据库表(大约有140列,因此我不会全部显示):

“插入AMS_ASSET_CS_IFACEOUT VALUES('abcdef','abcdef',to_date('2010-01-31','YYYY-MM-DD'),...)”

然后几秒钟后我运行以下代码片段:

    /// <summary>
    /// Function: GetRecord
    /// Description: Creates a new AMS-Asset and populates the
    /// properties of this asset by evaluating properties provided
    /// by the OracleDataReader.
    /// </summary>
    /// <param name="reader"> One record of information from the open connection.</param>
    /// <returns> A fully created AMS-Asset record. </returns>
    private static AmsAsset GetRecord(OracleDataReader reader)
    {
        AmsAsset newRecord = new AmsAsset();

        for (int propertyIndex = 0; propertyIndex < reader.FieldCount; propertyIndex++)
        {
            string propertyName = reader.GetName(propertyIndex).ToLower();
            string propertyValue = reader.GetValue(propertyIndex).ToString();
            int propertyValueAsInteger = 0;

            bool isPropertyAnInteger = Int32.TryParse(propertyValue, out propertyValueAsInteger);

            if (isPropertyAnInteger)
            {
                newRecord.GetType().GetProperty(propertyName).SetValue(newRecord, propertyValueAsInteger, null);
            }
            else
            {
                newRecord.GetType().GetProperty(propertyName).SetValue(newRecord, propertyValue, null);
            }
        }

        return newRecord;
    }

我插入数据库的日期值现在返回为“1/31/2010 12:00:00 AM。”

我不完全确定为什么......我的选择是什么?我是否需要将转换格式从我正在回复的格式

中编码

此致

肖恩安德森

1 个答案:

答案 0 :(得分:1)

由于您使用明确的“YYYY-MM-DD”格式日期插入数据库,因此它正确存储在数据库中。

当您将其读出并显示该日期时,格式取决于您的区域设置。

我建议您使用显式格式说明符进行显示。