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?

有帮助吗?

解决方案

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?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top