2011-08-09 31 views
1

我想一些數據的時間戳的接收存儲這樣的變量:分配當前時間戳到一個變量

DateTime timetora = DateTime.Now; 
DateTime receptiontimestamp; 
receptiontimestamp = timetora; 

,但我認爲作爲timetora總是進步receptiontimestamp不相同。但我希望它保持不變,並指出接待時刻不在現在。 我在做什麼錯?

+0

我將不得不檢查所有的接待是否發生在同一秒鐘。因爲這就是它所顯示的。不管怎樣,謝謝 – redfrogsbinary

回答

1

它不會繼續「前進」

當你這樣做:

DateTime timetora = DateTime.Now; 

timetora現在固定到了那個時候(因此是任何其他日期時間設置到timetora)沒有什麼錯與你寫的是什麼。

1

您輸入的密碼將從timetora複製到receptiontimestamp。它不會繼續前進。例如:

DateTime before = DateTime.Now; 
Thread.Sleep(10000); 
DateTime after = before; 

Console.WriteLine("Before: {0}", before); 
Console.WriteLine("After: {0}", after); 

這兩條線將表現出同樣的時間 - 他們不會顯示10秒差異。據我所知,這就是你想要的,對吧?

0

日期時間是一個值類型,所以

DateTime timetora = DateTime.Now; 

創建當前日期時間的副本。 timetora在您稍後訪問時不會增加。