将Oracle日期转换为c#DateTime [英] Convert Oracle Date to c# DateTime

查看:274
本文介绍了将Oracle日期转换为c#DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Date的oracle数据库读取记录,然后将其转换为ASP.NET c#DateTime对象。问题是,它拾起日期,但不是时间。我使用的命令是:

I am trying to read a record from oracle database of type Date and then convert it to ASP.NET c# DateTime object. Problem is, it picks up the date but not the time. Command I'm using is:

DateTime dt = Convert.ToDateTime(ds.Tables[0].Rows[0][0].ToString());

如果我尝试打印 ds.Tables [0] .Rows [0 ] [0] .ToString()然后它也显示时间。任何人都知道如何解决这个问题?

If I try to print ds.Tables[0].Rows[0][0].ToString() then it shows the time as well. Anyone know how to get around this?

我的oracle日期字段的值/格式为: 2013-01-01 14:14:14

My oracle date field has a value/format of:2013-01-01 14:14:14

推荐答案

这是:

DateTime dateTime = DateTime.ParseExact(ds.Tables[0].Rows[0][0].ToString(), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);

使用指定的格式解析,不依赖于线程文化。

parses using specified format and does not depend on thread culture.

这篇关于将Oracle日期转换为c#DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆