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

  • 相关阅读:
    Java 集合类
    Java 中的四种引用及垃圾回收策略
    Java 类的加载过程(阿里面试题)
    JMeter进行一次简单的压力测试
    python使用 HTMLTestRunner.py生成测试报告
    python读取配置文件
    python的IDE工具-- Pycharm
    selenium webdriver+python基本操作
    SQL开发测试使用基础
    python学习笔记
  • 原文地址:https://www.cnblogs.com/lzugis/p/6539936.html
Copyright © 2011-2022 走看看