TimeSpan 的 Milliseconds 和 TotalMilliseconds 有啥区别?

有小伙伴问到

TimeSpan的 Milliseconds和TotalMilliseconds有啥区别啊? 我用TimeSpan.FromSeconds(3600).Milliseconds就获取到是0 如果用TotalMilliseconds就是360000

有码有解

using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime dateTime = new DateTime(year: 2019, month: 08, day: 28, hour: 12, minute: 01, second: 02, millisecond: 03);
            //long ticks = DateTime.Now.Ticks;
            long ticks = dateTime.Ticks;
            Console.WriteLine(value: $"ticks = {ticks}");

            TimeSpan timeSpan = TimeSpan.FromTicks(value: ticks);
            Console.WriteLine(value: $"时间毫秒数(timeSpan.Milliseconds) = {timeSpan.Milliseconds}");
            Console.WriteLine(value: $"时间总毫秒数(timeSpan.TotalMilliseconds) = {timeSpan.TotalMilliseconds}");

            Console.ReadKey();
        }
    }
}

原文地址:https://www.cnblogs.com/taadis/p/12125805.html