在Datacontext中保存DateTime会设置错误的毫秒数(Saving DateTime in Datacontext sets wrong milliseconds)

编程入门 行业动态 更新时间:2024-10-24 10:27:03
在Datacontext中保存DateTime会设置错误的毫秒数(Saving DateTime in Datacontext sets wrong milliseconds)

我正在构建一个Windows Phone 8应用程序,我需要有毫秒的精度。 数据上下文如下:private DateTime _date;

[Column] public DateTime Date { get { return _date; } set { NotifyPropertyChanging("ItemDate"); _date= value; NotifyPropertyChanged("ItemDate"); } }

参考这个问题: 从XML转换为SQL Server datetime时出现毫秒错误我理解DataContext可能面临类似的问题。 更具体地说,DataContext的毫秒返回值有时高1或更低 - 取决于滴答的数量。

所以解决这个问题的唯一方法是将IntTime保存在Int64中,以毫秒为单位? 还有其他更好的解决方法吗?

I am building a Windows Phone 8 application where I need to have milliseconds precision. The data context is as follows: private DateTime _date;

[Column] public DateTime Date { get { return _date; } set { NotifyPropertyChanging("ItemDate"); _date= value; NotifyPropertyChanged("ItemDate"); } }

In reference to this question: Milliseconds wrong when converting from XML to SQL Server datetime I understand that DataContext might be facing similar problems. More specifically the return value of milliseconds from the DataContext is sometimes 1 ms higher or lower – depending on the number of ticks.

So the only solution to this is to save the DateTime in an Int64 as milliseconds? Is there any other better way to solve it?

最满意答案

如果你需要用这些数据进行计算,你需要自己做一些事情。 在内部,DateTime将Milliseconds存储为Int32 ,但这应该足够了。

如果您只是显示此数据,而不是依赖于DateTime类的基础属性和行为。 你能不能把它作为字符串存储/显示?

If you need to perform calculations with this data them you'll need to do something with this yourself. Internally, DateTime stores Milliseconds as an Int32 so that should be sufficient though.

If you're just displaying this data, rather than rely on the underlying properties and behaviour of the DateTime class. Could you not just store/display it as a string?

更多推荐

本文发布于:2023-08-06 15:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1451938.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   DateTime   Datacontext   Saving   milliseconds

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!