c# 中的TimeSpan类

c# 中的TimeSpan类对于TimeSpan不是很清楚,对于其中的代码不甚了解,因此,对于其中所有函数进行输出,就能完整的理解了c#中的TimeSpan了。usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading;namespaceCSDailyPrac

对于TimeSpan不是很清楚,对于其中的代码不甚了解,因此,对于其中所有函数进行输出,就能完整的理解了c#中的TimeSpan了。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace CSDailyPractice
{
    class Program
    {
        static void Main(string[] args)
        {
            TimeSpan t1 = DateTime.Now.TimeOfDay;
            Console.WriteLine("当前日期:   {0}",t1);
            Console.WriteLine("tick是:   {0}", t1.Ticks);
            Console.WriteLine("Hours:   {0}", t1.Hours);
            Console.WriteLine("Minutes:   {0}", t1.Minutes);
            Console.WriteLine("Second:   {0}", t1.Seconds);
            Console.WriteLine("MilliSeconds:   {0}", t1.Milliseconds);
            Console.WriteLine("TotalDays:   {0}",t1.TotalDays);
            Console.WriteLine("TotalHour:   {0}",t1.TotalHours);
            Console.WriteLine("TotalSeconds:   {0}", t1.TotalSeconds);
            Console.WriteLine("TotalMilliSeconds:   {0}", t1.TotalMilliseconds);
            
            Thread.Sleep(2000);
            Console.WriteLine("\n\n\n");

            TimeSpan t2 = DateTime.Now.TimeOfDay;
            Console.WriteLine("当前日期:   {0}", t2);
            Console.WriteLine("tick是:   {0}", t2.Ticks);
            Console.WriteLine("Hours:   {0}", t2.Hours);
            Console.WriteLine("Minutes:   {0}", t2.Minutes);
            Console.WriteLine("Second:   {0}", t2.Seconds);
            Console.WriteLine("MilliSeconds:   {0}", t2.Milliseconds);
            Console.WriteLine("TotalDays:   {0}", t2.TotalDays);
            Console.WriteLine("TotalHour:   {0}", t2.TotalHours);
            Console.WriteLine("TotalSeconds:   {0}", t2.TotalSeconds);
            Console.WriteLine("TotalMilliSeconds:   {0}", t2.TotalMilliseconds);

            Console.WriteLine("\n\n\n");
            TimeSpan result = t2 - t1;
            Console.WriteLine("当前日期:   {0}", result);
            Console.WriteLine("tick是:   {0}", result.Ticks);
            Console.WriteLine("Hours:   {0}", result.Hours);
            Console.WriteLine("Minutes:   {0}", result.Minutes);
            Console.WriteLine("Second:   {0}", result.Seconds);
            Console.WriteLine("MilliSeconds:   {0}", result.Milliseconds);
            Console.WriteLine("TotalDays:   {0}", result.TotalDays);
            Console.WriteLine("TotalHour:   {0}", result.TotalHours);
            Console.WriteLine("TotalSeconds:   {0}", result.TotalSeconds);
            Console.WriteLine("TotalMilliSeconds:   {0}", result.TotalMilliseconds);
        }
    }
}

运行结果如下:

c# 中的TimeSpan类

直接看代码运行结果就能明白各个函数的意思了。

今天的文章c# 中的TimeSpan类分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/13211.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注