本文整理匯總了C#中System.DateTime.Millisecond屬性的典型用法代碼示例。如果您正苦於以下問題:C# DateTime.Millisecond屬性的具體用法?C# DateTime.Millisecond怎麽用?C# DateTime.Millisecond使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類System.DateTime
的用法示例。
在下文中一共展示了DateTime.Millisecond屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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;
示例2: DateTime
DateTime date1 = new DateTime(2008, 1, 1, 0, 30, 45, 125);
Console.WriteLine("Milliseconds: {0:fff}",
date1); // displays Milliseconds: 125
示例3: DateTime
DateTime date2 = new DateTime(2008, 1, 1, 0, 30, 45, 125);
Console.WriteLine("Date: {0:o}",
date2);
輸出:
Date: 2008-01-01T00:30:45.1250000
示例4: DateTime
DateTime date3 = new DateTime(2008, 1, 1, 0, 30, 45, 125);
Console.WriteLine("Date with milliseconds: {0:MM/dd/yyy HH:mm:ss.fff}",
date3);
輸出:
Date with milliseconds: 01/01/2008 00:30:45.125
示例5: 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()
{
DateTime myDateTime4 = new DateTime(0);
TimeSpan myTimeSpan = new TimeSpan(4, 12, 10);
myDateTime4 += myTimeSpan;
DisplayDateTime("myDateTime4", myDateTime4);
}
}