zoukankan      html  css  js  c++  java
  • C#中获取系统时间 LZU

            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);
            }

  • 相关阅读:
    html标签笔记
    C语言中的函数基础
    数组
    循环控制结构程序(goto、while、dowhile、 for)
    if语句+switch
    分支程序设计
    字符数据的输入与输出
    各类数值型数据之间的混合运算
    c语言概述及如何上机运行c程序
    [记录] Ubuntu 配置Apache虚拟站点
  • 原文地址:https://www.cnblogs.com/lzugis/p/6539936.html
Copyright © 2011-2022 走看看