Question

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?

Était-ce utile?

La solution

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?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top