DateTimeOffset.Millisecond 屬性

定義

取得目前 DateTimeOffset 物件所表示之時間的毫秒數元件。

public:
 property int Millisecond { int get(); };
public int Millisecond { get; }
member this.Millisecond : int
Public ReadOnly Property Millisecond As Integer

屬性值

Int32

目前 DateTimeOffset 物件的毫秒數元件,以 0 到 999 之間的整數表示。

範例

下列範例使用自訂格式規範和直接存取 Millisecond 屬性,顯示 物件的毫秒 DateTimeOffset 數。

DateTimeOffset date1 = new DateTimeOffset(2008, 3, 5, 5, 45, 35, 649,
                                new TimeSpan(-7, 0, 0));
Console.WriteLine("Milliseconds value of {0} is {1}.",
                  date1.ToString("MM/dd/yyyy hh:mm:ss.fff"),
                  date1.Millisecond);
// The example produces the following output:
//
// Milliseconds value of 03/05/2008 05:45:35.649 is 649.
let date1 = DateTimeOffset(2008, 3, 5, 5, 45, 35, 649, TimeSpan(-7, 0, 0))
printfn $"""Milliseconds value of {date1.ToString "MM/dd/yyyy hh:mm:ss.fff"} is {date1.Millisecond}."""
                
// The example produces the following output:
//
// Milliseconds value of 03/05/2008 05:45:35.649 is 649.
Dim date1 As New DateTimeOffset(2008, 3, 5, 5, 45, 35, 649, _
                                New TimeSpan(-7, 0, 0))
Console.WriteLine("Milliseconds value of {0} is {1}.", _
                  date1.ToString("MM/dd/yyyy hh:mm:ss.fff"), _
                  date1.Millisecond)
' The example produces the following output:
'
' Milliseconds value of 03/05/2008 05:45:35.649 is 649.

備註

您也可以使用 「fff」 自訂格式規範呼叫 ToString 方法,以建立物件的毫秒元件的字串表示 DateTimeOffset

如果您依賴 或 UtcNow 之類的 Now 屬性來精確追蹤經過的毫秒數,時間毫秒元件的精確度取決於系統時鐘的解析度。 在 Windows NT 3.5 和更新版本,以及 Windows Vista 作業系統上,時鐘的解析度大約是 10-15 毫秒。

適用於