C#中tick 与秒的对应关系

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Data.SqlClient;
using System.Text.RegularExpressions;

namespace ConsoleApplication8
{
    class Program
    {
        static void Main(string[] args)
        {
            long ticks1 = 10000000;
            TimeSpan ts = new TimeSpan(ticks1);
            Console.WriteLine("{0} tick 相当于 {1} 秒", ticks1, ts.TotalSeconds);
            DateTime dt1 = DateTime.Parse("2015-09-21 10:00:00");
            DateTime dt2 = DateTime.Parse("2015-09-21 10:00:01");
            ts = dt2.Subtract(dt1);
            Console.WriteLine("{0} 秒相当于 {1} tick", ts.TotalSeconds, ts.Ticks);

            long ticks2 = (long)10000000 * (long)10800; //注:10000000 * 10800 会有异常:在 checked 模式下,运算在编译时溢出
            ts = new TimeSpan(ticks2);
            Console.WriteLine(ts.TotalSeconds);

            Console.Read();
        }
    }
}


C#中tick 与秒的对应关系_第1张图片

你可能感兴趣的:(C#)