轮.NET日期时间毫秒,因此它可以适应的SQL Server毫秒 [英] Round .NET DateTime milliseconds, so it can fit SQL Server milliseconds

查看:253
本文介绍了轮.NET日期时间毫秒,因此它可以适应的SQL Server毫秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要datetime值转换为我将从SQL Server 2008中获得的价值。

I want to convert the datetime value to the value that I will get from SQL Server 2008.

SQL Server的截断毫秒到3位数,所以我已经截断毫秒。但问题是,你可以在这里看到:<一href=\"http://stackoverflow.com/questions/634122/milliseconds-wrong-when-converting-from-xml-to-sql-server-datetime\">http://stackoverflow.com/questions/634122/milliseconds-wrong-when-converting-from-xml-to-sql-server-datetime. SQL Server还拥有一个precision问题。

SQL Server truncate the milliseconds to 3 digits, so I truncate the milliseconds already. But the problem is that as you can see here: http://stackoverflow.com/questions/634122/milliseconds-wrong-when-converting-from-xml-to-sql-server-datetime. SQL Server also has an precision issue.

推荐答案

下面是你想要的:

using System.Data.SqlTypes; // from System.Data.dll

public static DateTime RoundToSqlDateTime(DateTime date)
{
  return new SqlDateTime(date).Value;
}

这篇关于轮.NET日期时间毫秒,因此它可以适应的SQL Server毫秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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