DateTimeOffset.Month Свойство
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Возвращает компонент месяца даты, представленной текущим DateTimeOffset объектом.
public:
property int Month { int get(); };
public int Month { get; }
member this.Month : int
Public ReadOnly Property Month As Integer
Значение свойства
Компонент месяца текущего DateTimeOffset объекта, выраженный как целое число от 1 до 12.
Примеры
В следующем примере показан компонент DateTimeOffset месяца значения тремя разными способами:
Извлекая значение свойства Month.
Вызывая ToString(String) метод с описательом формата "M".
Вызывая ToString(String) метод с описательом формата MM.
DateTimeOffset theTime = new DateTimeOffset(2008, 9, 7, 11, 25, 0,
DateTimeOffset.Now.Offset);
Console.WriteLine("The month component of {0} is {1}.",
theTime, theTime.Month);
Console.WriteLine("The month component of {0} is{1}.",
theTime, theTime.ToString(" M"));
Console.WriteLine("The month component of {0} is {1}.",
theTime, theTime.ToString("MM"));
// The example produces the following output:
// The month component of 9/7/2008 11:25:00 AM -08:00 is 9.
// The month component of 9/7/2008 11:25:00 AM -08:00 is 9.
// The month component of 9/7/2008 11:25:00 AM -08:00 is 09.
let theTime = DateTimeOffset(2008, 9, 7, 11, 25, 0, DateTimeOffset.Now.Offset)
printfn $"The month component of {theTime} is {theTime.Month}."
printfn $"""The month component of {theTime} is{theTime.ToString " M"}."""
printfn $"""The month component of {theTime} is {theTime.ToString "MM"}."""
// The example produces the following output:
// The month component of 9/7/2008 11:25:00 AM -08:00 is 9.
// The month component of 9/7/2008 11:25:00 AM -08:00 is 9.
// The month component of 9/7/2008 11:25:00 AM -08:00 is 09.
Dim theTime As New DateTimeOffset(#9/7/2008 11:25AM#, _
DateTimeOffset.Now.Offset)
Console.WriteLine("The month component of {0} is {1}.", _
theTime, theTime.Month)
Console.WriteLine("The month component of {0} is{1}.", _
theTime, theTime.ToString(" M"))
Console.WriteLine("The month component of {0} is {1}.", _
theTime, theTime.ToString("MM"))
' The example produces the following output:
' The month component of 9/7/2008 11:25:00 AM -08:00 is 9.
' The month component of 9/7/2008 11:25:00 AM -08:00 is 9.
' The month component of 9/7/2008 11:25:00 AM -08:00 is 09.
Комментарии
Свойство Month не влияет на значение Offset свойства.
Кроме того, можно создать строковое представление DateTimeOffset компонента месяца объекта, вызвав ToString метод с пользовательскими описателями формата "M" или "MM".