DateTime.Add(TimeSpan) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
public:
DateTime Add(TimeSpan value);
public DateTime Add(TimeSpan value);
member this.Add : TimeSpan -> DateTime
Public Function Add (value As TimeSpan) As DateTime
参数
- value
- TimeSpan
正时间间隔或负时间间隔。
返回
一个对象,其值为此实例所表示的日期和时间之和,以及表示的 value时间间隔。
例外
示例
以下示例演示了该方法 Add 。 它计算一周中的一天,从此刻起为 36 天(864 小时)。
// Calculate what day of the week is 36 days from this instant.
let today = DateTime.Now
let duration = TimeSpan(36, 0, 0, 0)
let answer = today.Add duration
printfn $"{answer:dddd}"
// Calculate what day of the week is 36 days from this instant.
System.DateTime today = System.DateTime.Now;
System.TimeSpan duration = new System.TimeSpan(36, 0, 0, 0);
System.DateTime answer = today.Add(duration);
System.Console.WriteLine("{0:dddd}", answer);
' Calculate what day of the week is 36 days from this instant.
Dim today As System.DateTime
Dim duration As System.TimeSpan
Dim answer As System.DateTime
today = System.DateTime.Now
duration = New System.TimeSpan(36, 0, 0, 0)
answer = today.Add(duration)
System.Console.WriteLine("{0:dddd}", answer)
注解
可以使用该方法 Add 在单个操作中添加多个时间间隔(天、小时、分钟、秒或毫秒)。 此方法的行为与加法运算符的行为相同。 该 DateTime 结构还支持每个时间间隔的专用加法方法(例如 AddDays, AddHours和 AddMinutes)。
该方法 Add 考虑了执行日期算术时的跃年数和一个月内的天数。
此方法不会更改此值 DateTime。 而是返回一个新 DateTime 值是此操作的结果。 Kind新DateTime实例的属性与当前实例的属性相同。