DateTimeOffset.Month 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取由当前 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 属性的值。
通过使用“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。