2011-08-06 61 views
8

我想在時間選擇器中從時間值中減去一秒鐘。我發現代碼添加到選取器值的第二個,但我不知道如何減去。如何在Windows Phone 7中從DateTime中減去秒數?

我應該怎麼做呢?

private static void CreateAlarm(DateTime time, string title) 
{ 
    var alarm = new Alarm(title) 
    { 
     Content = "You have a meeting with your team now.", 
     BeginTime = time.AddSeconds(10), 
    }; 
} 

private void SetAlarm_Click(object sender, RoutedEventArgs e) 
{ 
    CreateAlarm(Convert.ToDateTime(timePicker1.ValueString), textBox1.Text); 
} 

回答

16

只需添加一個減號:

EndTime = time.AddSeconds(-10)