c# datetime._C#| DateTime.Month属性与示例

c# datetime.

DateTime.Month属性 (DateTime.Month Property)

DateTime.Month Property is used to get the month component of this object. It's a GET property of DateTime class.

DateTime.Month属性用于获取此对象的月份组成部分。 这是DateTime类的GET属性。

Syntax:

句法:

    int DateTime.Month;

Return value:

返回值:

The return type of this Property is int, it returns an integer value i.e. month component of this object.

此Property的返回类型为int ,它返回一个整数值,即此对象的month分量。

Example to demonstrate example of DateTime.Month Property

示例,以演示DateTime.Month属性的示例

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //creating an object of DateTime class
            //and, initializing it with the current time 
            //using "Now"           
            DateTime dt = DateTime.Now;

            //getting month component 
            string month = dt.Month.ToString();

            //printing current date & time 
            Console.WriteLine("Current date & time is: " + dt.ToString());
            //printing the day of the week
            Console.WriteLine("Month is : " + month);

            //just to print a new line
            Console.WriteLine();
        }
    }
}

Output

输出量

Current date & time is: 10/24/2019 7:08:01 AM
Month is : 10


翻译自: https://www.includehelp.com/dot-net/datetime-month.aspx

c# datetime.

你可能感兴趣的:(c# datetime._C#| DateTime.Month属性与示例)