DateTimeOffset.Day 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取由当前 DateTimeOffset 对象所表示的月中的某一天。
public:
property int Day { int get(); };
public int Day { get; }
member this.Day : int
Public ReadOnly Property Day As Integer
属性值
当前 DateTimeOffset 对象的日组成部分,以 1 到 31 之间的一个值来表示。
示例
以下示例以三种不同的方式显示对象的 day 组件 DateTimeOffset :
通过检索属性的值 Day 。
通过使用“d”格式说明符调用 ToString(String) 方法。
通过使用“dd”格式说明符调用 ToString(String) 方法。
DateTimeOffset theTime = new DateTimeOffset(2007, 5, 1, 16, 35, 0,
DateTimeOffset.Now.Offset);
Console.WriteLine("The day component of {0} is {1}.",
theTime, theTime.Day);
Console.WriteLine("The day component of {0} is{1}.",
theTime, theTime.ToString(" d"));
Console.WriteLine("The day component of {0} is {1}.",
theTime, theTime.ToString("dd"));
// The example produces the following output:
// The day component of 5/1/2007 4:35:00 PM -08:00 is 1.
// The day component of 5/1/2007 4:35:00 PM -08:00 is 1.
// The day component of 5/1/2007 4:35:00 PM -08:00 is 01.
let theTime = DateTimeOffset(2007, 5, 1, 16, 35, 0, DateTimeOffset.Now.Offset)
printfn $"The day component of {theTime} is {theTime.Day}."
printfn $"""The day component of {theTime} is{theTime.ToString " d"}."""
printfn $"The day component of {theTime} is {theTime:dd}."
// The example produces the following output:
// The day component of 5/1/2007 4:35:00 PM -08:00 is 1.
// The day component of 5/1/2007 4:35:00 PM -08:00 is 1.
// The day component of 5/1/2007 4:35:00 PM -08:00 is 01.
Dim theTime As New DateTimeOffset(#5/1/2007 4:35PM#, _
DateTimeOffset.Now.Offset)
Console.WriteLine("The day component of {0} is {1}.", _
theTime, theTime.Day)
Console.WriteLine("The day component of {0} is{1}.", _
theTime, theTime.ToString(" d"))
Console.WriteLine("The day component of {0} is {1}.", _
theTime, theTime.ToString("dd"))
' The example produces the following output:
' The day component of 5/1/2007 4:35:00 PM -08:00 is 1.
' The day component of 5/1/2007 4:35:00 PM -08:00 is 1.
' The day component of 5/1/2007 4:35:00 PM -08:00 is 01.
注解
还可以通过使用“d”或“dd”自定义格式说明符调用ToString方法来创建对象的日期组件的字符串表示形式DateTimeOffset。