1

我以 1/1000 的全毫秒保真度记录了 JS 日期时间戳。(使用 SQL 我知道精度是 1/300)

我一直在使用.NET System.DateTime struct,但我没有看到毫秒存储在 SQL 中。

...   
 [ResponseTimeStamp] DATETIME         NOT NULL,
...

用 c#

//TimeCompleted is epoc 

    DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
    qr.ResponseTimeStamp = dtDateTime.AddMilliseconds(item.Responses.TimeCompleted); 

我现在正在尝试System.Data.SqlTypes.SqlDateTime使用

SqlDateTime dtDateTime = new SqlDateTime(1970, 1, 1, 0, 0, 0, 0);
qr.ResponseTimeStamp = SqlDateTime.Add(dtDateTime, item.Responses.TimeCompleted);

问题是该方法正在引发异常:

"message": "'System.Data.SqlTypes.SqlDateTime.Add(System.Data.SqlTypes.SqlDateTime, System.TimeSpan)' 的最佳重载方法匹配

我尝试将 from 转换epocTimeSpan,但签名需要我创建的 TimeSpan 但仍然引发异常。

TimeSpan newSpan = new TimeSpan(0, 0, 0, 0, item.Responses.TimeCompleted);

The best overloaded method match for 'System.Data.SqlTypes.SqlDateTime.Add(System.Data.SqlTypes.SqlDateTime, System.TimeSpan)' has some invalid arguments

4

1 回答 1

2

If you need to store the time down to the millisecond then you should be using a datetime2 or a datetimeoffset for your data.

Both these types allow for accuracy down to the millisecond unlike DateTime which only has a resolution of 3 milliseconds.

于 2016-08-02T14:41:11.317 回答