zoukankan      html  css  js  c++  java
  • DateTime和TimeSpan实例

    /*
      Example9_3.cs illustrates the use of DateTime and TimeSpan instances
    */
    
    using System;
    
    class Example9_3
    {
    
      public static void DisplayDateTime(
        string name, DateTime myDateTime
      )
      {
    
        Console.WriteLine(name + " = " + myDateTime);
    
        // display the DateTime's properties
        Console.WriteLine(name + ".Year = " + myDateTime.Year);
        Console.WriteLine(name + ".Month = " + myDateTime.Month);
        Console.WriteLine(name + ".Day = " + myDateTime.Day);
        Console.WriteLine(name + ".Hour = " + myDateTime.Hour);
        Console.WriteLine(name + ".Minute = " + myDateTime.Minute);
        Console.WriteLine(name + ".Second = " + myDateTime.Second);
        Console.WriteLine(name + ".Millisecond = " +
          myDateTime.Millisecond);
        Console.WriteLine(name + ".Ticks = " +
          myDateTime.Ticks);
    
      }
    
    
      public static void Main()
      {
    
        // create a DateTime instance, specifying the year,
        // month, and day
        int year = 2002;
        int month = 12;
        int day = 25;
        DateTime myDateTime = new DateTime(year, month, day);
    
        // create a DateTime instance, specifying the year,
        // month, day, hour, minute, second, and millisecond
        int hour = 23;
        int minute = 30;
        int second = 12;
        int millisecond = 5;
        DateTime myDateTime2 =
          new DateTime(year, month, day, hour, minute, second, millisecond);
    
        // create a DateTime instance, specifying the year,
        // month, day, and JulianCalendar object
        System.Globalization.JulianCalendar myCalendar =
          new System.Globalization.JulianCalendar();
        DateTime myDateTime3 =
          new DateTime(year, month, day, myCalendar);
    
        // create a DateTime instance, specifying the number of ticks
        DateTime myDateTime4 = new DateTime(0);
    
        // display the various DateTime instances
        DisplayDateTime("myDateTime", myDateTime);
        DisplayDateTime("myDateTime2", myDateTime2);
        DisplayDateTime("myDateTime3", myDateTime3);
        DisplayDateTime("myDateTime4", myDateTime4);
    
        // create a TimeSpan instance, and add it to myDateTime4
        TimeSpan myTimeSpan = new TimeSpan(4, 12, 10);
        myDateTime4 += myTimeSpan;
        DisplayDateTime("myDateTime4", myDateTime4);
    
      }
    
    }
    
  • 相关阅读:
    2019-3-24
    模板
    试试Markdown编辑器
    Codeforces Round #529 (Div. 3) D. Circular Dance
    Codeforces Round #529 (Div. 3) C. Powers Of Two(数学????)
    poj 2566"Bound Found"(尺取法)
    poj 3273"Monthly Expense"(二分搜索+最小化最大值)
    二分搜索
    Codeforces Round #518 (Div. 2) B LCM
    2018.12.21 浪在ACM 集训队第十次测试赛
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2038238.html
Copyright © 2011-2022 走看看