簡體   English   中英

將TimeSpan添加到DateTime不起作用

[英]Add TimeSpan to DateTime doesn't work

我想在DateTime中添加新的時間值

我在Watch中的代碼:

tsStart {09:00:00}  System.TimeSpan
StartDateTime   {10/17/2014 12:00:00 AM}    System.DateTime

用於將TimeSpan添加到DateTime的c#代碼:

StartDateTime.Add(tsStart);

添加后Watch中的值

StartDateTime   {10/17/2014 12:00:00 AM}    System.DateTime

我做錯了什么?

DateTime是不可變類型。

DateTime newTime = StartDateTime.Add(tsStart);

在對JesseJames的評論中回答:

StartDateTime = StartDateTime.Add(tsStart);

DateTime Add函數將返回一個新的DateTime值,該值由DateTime和Added DateTime Value組成。 但是,不會更改DateTime值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM