英語で読む

次の方法で共有


DateTime.Millisecond プロパティ

定義

このインスタンスで表される日付のミリ秒の部分を取得します。

C#
public int Millisecond { get; }

プロパティ値

DateTime のミリ秒部分 (0 ~ 999)。

Millisecondプロパティの例を次に示します。

C#
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;

注釈

"fff" 書式指定子を Millisecond 使用して、 プロパティの文字列表現を表示できます。 たとえば、次のコードは、日付と時刻のミリ秒数を含む文字列をコンソールに表示します。

C#
DateTime date1 = new DateTime(2008, 1, 1, 0, 30, 45, 125);
Console.WriteLine("Milliseconds: {0:fff}",
                  date1);           // displays Milliseconds: 125

"o" 標準書式指定子を使用して、ミリ秒コンポーネントを日付と時刻の値の他のコンポーネントと共に表示することもできます。 次に例を示します。

C#
DateTime date2 = new DateTime(2008, 1, 1, 0, 30, 45, 125);
Console.WriteLine("Date: {0:o}",
                  date2);
// Displays the following output to the console:
//      Date: 2008-01-01T00:30:45.1250000

ただし、"o" 書式指定子は、ラウンド トリップまたは値の格納 DateTime よりも表示が少ないことを目的としています。 次の例に示すように、カスタム書式指定文字列を使用して、ミリ秒を他の日付と時刻のコンポーネントと共に表示することもできます。

C#
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);
// Displays the following output to the console:
//       Date with milliseconds: 01/01/2008 00:30:45.125

適用対象

製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0