DateTimeOffset.Month 属性   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取由当前 DateTimeOffset 对象所表示的日期的月份组成部分。
public:
 property int Month { int get(); };public int Month { get; }member this.Month : intPublic ReadOnly Property Month As Integer属性值
当前 DateTimeOffset 对象的月份组成部分,以 1 到 12 之间的一个整数来表示。
示例
以下示例以三种不同的方式显示值的月份组件 DateTimeOffset :
- 通过检索 属性的值 Month 。 
- 使用“M”格式说明符调用 ToString(String) 方法。 
- 使用“MM”格式说明符调用 ToString(String) 方法。 
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.
注解
还可以使用“M”或“MM”自定义格式说明符调用 ToString 方法,创建对象的月份组件的字符串表示形式DateTimeOffset。