当前位置: 首页>>代码示例>>C#>>正文


C# DateTime.Year属性代码示例

本文整理汇总了C#中System.DateTime.Year属性的典型用法代码示例。如果您正苦于以下问题:C# DateTime.Year属性的具体用法?C# DateTime.Year怎么用?C# DateTime.Year使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在System.DateTime的用法示例。


在下文中一共展示了DateTime.Year属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1:

System.DateTime moment = new System.DateTime(
                                1999, 1, 13, 3, 57, 32, 11);
// Year gets 1999.
int year = moment.Year;

// Month gets 1 (January).
int month = moment.Month;

// Day gets 13.
int day = moment.Day;

// Hour gets 3.
int hour = moment.Hour;

// Minute gets 57.
int minute = moment.Minute;

// Second gets 32.
int second = moment.Second;

// Millisecond gets 11.
int millisecond = moment.Millisecond;
开发者ID:.NET开发者,项目名称:System,代码行数:22,代码来源:DateTime.Year

示例2: Main

//引入命名空间
using System;
using System.Globalization;
using System.Threading;

public class YearMethodExample
{
    public static void Main()
    {
      // Initialize date variable and display year
      DateTime date1 = new DateTime(2008, 1, 1, 6, 32, 0);
      Console.WriteLine(date1.Year);                    // Displays 2008
      
      // Set culture to th-TH
      Thread.CurrentThread.CurrentCulture = new CultureInfo("th-TH");
      Console.WriteLine(date1.Year);                    // Displays 2008
      
      // display year using current culture's calendar 
      Calendar thaiCalendar = CultureInfo.CurrentCulture.Calendar;
      Console.WriteLine(thaiCalendar.GetYear(date1));   // Displays 2551
      
      // display year using Persian calendar
      PersianCalendar persianCalendar = new PersianCalendar();
      Console.WriteLine(persianCalendar.GetYear(date1)); // Displays 1386 
   }
}
开发者ID:.NET开发者,项目名称:System,代码行数:26,代码来源:DateTime.Year

示例3: DisplayDateTime

//引入命名空间
using System;

class MainClass {

  public static void DisplayDateTime(string name, DateTime myDateTime) {
    Console.WriteLine(name + " = " + myDateTime);
    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()
  {
    
    int year = 2002;
    int month = 12;
    int day = 25;
    DateTime myDateTime = new DateTime(year, month, day);
    DisplayDateTime("myDateTime", myDateTime);
  }

}
开发者ID:C#程序员,项目名称:System,代码行数:28,代码来源:DateTime.Year


注:本文中的System.DateTime.Year属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。