首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >C#中获取系统时间

C#中获取系统时间

作者头像
牛老师讲GIS
发布2018-10-23 16:03:38
发布2018-10-23 16:03:38
4.6K00
代码可运行
举报
运行总次数:0
代码可运行
代码语言:javascript
代码运行次数:0
运行
复制
        static void Main(string[] args)
        {
            Console.WriteLine("获取日期加时间:");
            string strDateandTime = DateTime.Now.ToString();
            Console.WriteLine(strDateandTime);

            Console.WriteLine("获取日期:");           
            string strDate1 = DateTime.Now.ToLongDateString();
            Console.WriteLine(strDate1);
            string strDate2 = DateTime.Now.ToShortDateString();
            Console.WriteLine(strDate2);
            string strDate3 = DateTime.Now.ToString("yyyy年MM月dd日");
            Console.WriteLine(strDate3);

            Console.WriteLine("获取时间:");
            string strTime1 = DateTime.Now.ToLongTimeString();
            Console.WriteLine(strTime1);
            string strTime2 = DateTime.Now.ToShortTimeString();
            Console.WriteLine(strTime2);
            string strTime3 = DateTime.Now.ToString("hh时mm分ss秒");
            Console.WriteLine(strTime3);

            Console.Write("获取年:");
            string strYear = DateTime.Now.Year.ToString();
            Console.WriteLine(strYear);

            Console.Write("获取月:");
            string strMonth = DateTime.Now.Month.ToString();
            Console.WriteLine(strMonth);

            Console.Write("获取日:");
            string strDate = DateTime.Now.DayOfYear.ToString();
            Console.WriteLine(strDate);

            Console.Write("获取星期:");
            string strDay = DateTime.Now.DayOfWeek.ToString();
            Console.WriteLine(strDay);

            Console.Write("获取时:");
            string strHour = DateTime.Now.Hour.ToString();
            Console.WriteLine(strHour);

            Console.Write("获取分:");
            string strMinute = DateTime.Now.Minute.ToString();
            Console.WriteLine(strMinute);

            Console.Write("获取秒:");
            string strSecond = DateTime.Now.Second.ToString();
            Console.WriteLine(strSecond);


            Console.WriteLine("按任意键结束……");
            Console.ReadKey(true);
        }
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2013年04月03日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档