ToDouble() публичный статический Метод

Converts a DateTime instance (assumed to represent local time) to Unix time (UTC) with a precision of over a second (i.e. fractional part of the returned float-point value is fractions of a second).
public static ToDouble ( System.DateTime time ) : double
time System.DateTime
Результат double
Пример #1
0
        public void Milliseconds()
        {
            DateTime     t1 = new DateTime(2006, 7, 17, 10, 56, 56, 456);
            const double u1 = 1153133816.456;

            DateTime     t2 = new DateTime(2006, 7, 17, 11, 00, 44, 567);
            const double u2 = 1153134044.567;

            DateTime ut1 = UnixTime.ToDateTime(u1).ToUniversalTime();

            Assert.AreEqual(t1, ut1, "ms expected = {0}, ms actual = {1}", t1.Millisecond, ut1.Millisecond);

            DateTime ut2 = UnixTime.ToDateTime(u2).ToUniversalTime();

            Assert.AreEqual(t2, ut2, "ms expected = {0}, ms actual = {1}", t2.Millisecond, ut2.Millisecond);

            Assert.AreEqual(u1, UnixTime.ToDouble(t1.ToLocalTime()), 0.0001);
            Assert.AreEqual(u2, UnixTime.ToDouble(t2.ToLocalTime()), 0.0001);
        }
Пример #2
0
        public void Milliseconds()
        {
            DateTime     t1 = new DateTime(2006, 7, 17, 10, 56, 56, 456);
            const double u1 = 1153133816.456;

            DateTime     t2 = new DateTime(2006, 7, 17, 11, 00, 44, 567);
            const double u2 = 1153134044.567;

            DateTime ut1 = UnixTime.ToDateTime(u1).ToUniversalTime();

            Assert.AreEqual(t1, ut1, "ms expected = {0}, ms actual = {1}", t1.Millisecond, ut1.Millisecond);

            DateTime ut2 = UnixTime.ToDateTime(u2).ToUniversalTime();

            Assert.AreEqual(t2, ut2, "ms expected = {0}, ms actual = {1}", t2.Millisecond, ut2.Millisecond);

            Assert.AreEqual(u1, UnixTime.ToDouble(t1.ToLocalTime()), 0.0001);
            Assert.AreEqual(u2, UnixTime.ToDouble(t2.ToLocalTime()), 0.0001);

            Assert.AreEqual(new DateTime(1098, 7, 6, 5, 43, 21, 234), UnixTime.ToDateTime(-27501531398.766).ToUniversalTime());
            Assert.AreEqual(UnixTime.EpochUtc.AddMilliseconds(+123), UnixTime.ToDateTime(0, +123).ToUniversalTime());
            Assert.AreEqual(UnixTime.EpochUtc.AddMilliseconds(-123), UnixTime.ToDateTime(0, -123).ToUniversalTime());
        }