转换为datetime从Oracle [英] Convert to datetime from Oracle

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

问题描述

我知道有很多类似的问题,但我无法找到我一直在寻找



下面是我的Oracle日期:



 字符串testdate =2014年1月7日15:00:00.0000000 

这是我试图转换为日期时间:

  DateTime.ParseExact(testdate,YYYY-MM-DD HH:MM:SS.FFF,CultureInfo.InvariantCulture)

这抛出一个格式异常。有任何想法吗?



我的快速测试也会引发该字符串不是有效的datetime例外。快速测试:

  Console.WriteLine(DateTime.ParseExact(testdate,YYYY-MM-DD HH:MM:SS.FFF CultureInfo.InvariantCulture).ToShortDateString()); 


解决方案

我的启动的通过尝试避免让它作为摆在首位的字符串。确保您使用适当的数据类型在Oracle中,你应该能够调用 GetDateTime 上相应的的DataReader (或者你使用任何)。



如果您的必须的解析文本,那么你需要指定匹配的格式价值 - 所以使用3 7 ˚F!而非,因为你的价值已经0.0000000末

  DateTime.ParseExact(testdate,YYYY-MM-DD HH:MM:ss.fffffff,
CultureInfo.InvariantCulture)

但同样,我的强烈的恳请您以避免处理值作为文本的。


i know there are a lot of similar questions, but I couldn't find what I was looking for.

Here is my oracle date:

string testdate= "2014-01-07 15:00:00.0000000";

And here is how I tried to convert to datetime:

DateTime.ParseExact(testdate, "yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture)

This throws a format exception. Any ideas?

My quick test also throws the string not valid datetime exception. Quick test:

Console.WriteLine(DateTime.ParseExact(testdate, "yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture).ToShortDateString());    

解决方案

I'd start by trying to avoid getting it as a string in the first place. Make sure you're using the appropriate data type in Oracle, and you should be able to call GetDateTime on the appropriate DataReader (or whatever you're using).

If you must parse it as text, then you need to specify a format which matches the value - so use 7 fs instead of 3, given that your value has ".0000000" at the end.

DateTime.ParseExact(testdate, "yyyy-MM-dd HH:mm:ss.fffffff",
                    CultureInfo.InvariantCulture)

But again, I'd strongly urge you to avoid having to deal with the value as text at all.

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

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