如何格式化日期从Oracle到有效的日期时间在c# [英] How to format a date from Oracle to a valid datetime in c#

查看:209
本文介绍了如何格式化日期从Oracle到有效的日期时间在c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将Oracle的日期格式化为c#中有效的 DateTime
$ b

那么... oracle格式字符串与C# DateTime 格式字符串有点不同,所以我不能使用该格式字符串作为解析的参数。我使用的是Devart / CoreLab,但是它们的 OracleDate .Parse似乎真的很奇怪,并不适合我。我如何正确解析它?我是否必须使用 TO_DATE / TO_CHAR 来调用对db的查询才能获得转换?或者说我必须将每个oracle格式的字符串元素映射到一个C#格式的字符串元素?

编辑:而Oracle和C#的格式字符串是不同的,比如MON的MMM ...

编辑2:更多的说明:基本上我会有字符串是oracle-date-in-string,例如DD-MON-YY,DD-MON-RR,YYYY / RM / DD等格式, ...等等



我希望能够正确解析它们到C# DateTime 中,这样我可以将它们设置为参数(它期望C# DateTime ),问题是这些oracle-date-format-pattern与C#DateTime-parse-format-模式。



我怀疑某处可能存在某些可以执行某些操作的函数

  DateTime dt = ParseDatestringWithSpecifiedOracleDatePatternIntoCSharpDateTime(08-OCT-85,DD-MON-YY); 



试试:

对不起,但我找不到它了。

  DateTime.ParseExact(08-OCT-85,dd-MMM-yy,System.Globalization.CultureInfo.InvariantCulture)


How to format a date from Oracle to a valid DateTime in c#?

So... the oracle format string is a bit different from the C# DateTime format string, so I can't use that format-string as an argument for the parse. I am using Devart/CoreLab but their OracleDate.Parse seems to be really strange and not working for me. How can I parse it correctly? Do I have to call a query to the db with a TO_DATE/TO_CHAR just to get a conversion? Or that I have to map each oracle format string element into a C# format string element?

edit: And the format string of Oracle and C# are different, such as MON instead of MMM...

edit2: more clarification: Basically I would have strings that are oracle-date-in-string, e.g. "08-OCT-85", and I am also able to get the oracle format pattern that these date string is following, such as "DD-MON-YY", "DD-MON-RR", "YYYY/RM/DD"... etc

I would like to be able to parse them into a C# DateTime properly so that I can set them to Parameter (which expects C# DateTime), and the problem is these oracle-date-format-pattern is not the same as the C# DateTime-parse-format-pattern.

I suspect somewhere out there might exist some function that can do something like

DateTime dt = ParseDatestringWithSpecifiedOracleDatePatternIntoCSharpDateTime("08-OCT-85", "DD-MON-YY); 

right? But I can't find it yet :(

解决方案

Try:

DateTime.ParseExact("08-OCT-85", "dd-MMM-yy", System.Globalization.CultureInfo.InvariantCulture)

这篇关于如何格式化日期从Oracle到有效的日期时间在c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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