[英]What format string can I use to parse an Oracle TIMESTAMP?
I have the following value stored in an Oracle TIMESTAMP
column 05-JAN-18 12.00.00.000000000 AM
. 我在Oracle
TIMESTAMP
列05-JAN-18 12.00.00.000000000 AM
存储了以下值。 I am trying to parse the values and convert them to something that is SQL Server DATETIME
friendly. 我正在尝试解析这些值并将它们转换为SQL Server
DATETIME
友好的值。 This is what I am trying to do: 这就是我想要做的:
DateTime result;
DateTime.TryParseExact(
"05-JAN-18 12.00.00.000000000 AM",
"dd-MMM-yy hh.mm.ss.fffffff tt",
new CultureInfo("en-US"), DateTimeStyles.None,
out result))
except this is not working because the format string does not have the precision to parse all of the milliseconds. 除此之外这是行不通的,因为格式字符串不具有解析所有毫秒的精度。 How can I get around this?
我该如何解决? Is there a different format string I can use, or a better way to convert Oracle
TIMESTAMP
to DateTime
? 是否可以使用其他格式的字符串,或者将Oracle
TIMESTAMP
转换为DateTime
的更好方法?
For your modified question and data you need fffffff00
for millisecond part. 对于修改后的问题和数据,您需要
fffffff00
为单位的fffffff00
。
DateTime result;
DateTime.TryParseExact(
"10-JAN-12 03.51.35.028000000 PM",
"dd-MMM-yy hh.mm.ss.fffffff00 tt",
new CultureInfo("en-US"), DateTimeStyles.None,
out result);
For more see: Custom Date and Time Format Strings 有关更多信息,请参见: 自定义日期和时间格式字符串
In .NET, maximum number of significant digits of the seconds is seven which is represent as fffffff
. 在.NET中, 秒的最大有效位数为7 ,表示为
fffffff
。
That's why you have to remove 00
part on your original string's fraction part if you want to parse successfully. 这就是为什么要成功解析, 必须删除原始字符串的小数部分的
00
部分的原因。
DateTime result;
DateTime.TryParseExact(
"05-JAN-18 12.00.00.0000000 AM",
"dd-MMM-yy hh.mm.ss.fffffff tt",
new CultureInfo("en-US"), DateTimeStyles.None,
out result))
Or you can use string delimiter (if these two digits are always 00
) like; 或者,您可以使用字符串定界符(如果这两个数字始终为
00
),例如;
DateTime result;
DateTime.TryParseExact(
"05-JAN-18 12.00.00.000000000 AM",
"dd-MMM-yy hh.mm.ss.fffffff'00' tt",
new CultureInfo("en-US"), DateTimeStyles.None,
out result))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.