I am trying to subtract a second from time value in a time picker. I found the code to add a second to the picker value, but I couldn't figure out how to subtract.
How should I go about doing it?
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);
}
Subtract(DateTime) This method is used to subtract the specified date and time from this instance. Syntax: public TimeSpan Subtract (DateTime value); Return Value: This method returns a time interval that is equal to the date and time represented by this instance minus the date and time represented by value.
DateTime. Subtract(TimeSpan) returns a new DateTime that subtracts the specified time interval (TimeSpan value) from the current instance. The Subtract() method subtract TimeSpan object from the DateTime object.
Add(new TimeSpan(0,-45,0)); Or you can also use the DateTime. Subtract(TimeSpan) method analogously.
Just add a minus sign:
EndTime = time.AddSeconds(-10)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With