[英]Recordset to timespan
I have a table which have a time(7) type field named Shift_Start_Time 我有一个表,其中有一个名为Shift_Start_Time的time(7)类型字段
After creating the recordset RST. 创建记录集RST之后。
I want to keep it in a timespan 我想保持一段时间
TimeSpan TT;
TT = RST.Fields("Shift_Start_Time").Value;
or keep it into milliseconds as integer 或以毫秒为单位保持整数
int int1;
int1 = RST.Fields("Shift_Start_Time").Value;
How can i do that? 我怎样才能做到这一点? Every step i have taked it gives the similer errors.
我采取的每一个步骤都给出了类似的错误。 for example:
例如:
Convert.ToInt64(RST.Fields("Shift_Start_Time").Value);
"Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'."
You have to use it as an Int64
or a DateTimeOffset
. 您必须将其用作
Int64
或DateTimeOffset
。 The code might look something like this: 该代码可能看起来像这样:
var bytes = RST.Fields("Shift_Start_Time").Value as byte[];
var intVal = BitConverter.ToInt64(bytes, 0);
var dtOffset = new DateTimeOffset(intVal, new TimeSpan(-5, 0, 0));
In this example I've used a static -5
offset for EST
in the TimeSpan
. 在此示例中,我在
TimeSpan
为EST
使用了静态-5
偏移量。 See this article for more detail. 有关更多详细信息, 请参见本文 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.