The purpose of my method is to get the currentTime, and set it back for 20 minutes. For what I can see, my method is correct, but the output shows something else.
This i my code:
DateTime currentTime = DateTime.Now;
double minuts = -20;
currentTime.AddMinutes(minuts);
Console.WriteLine("Nuværende tid: "+currentTime);
The output are as followed:
25-11-2011 14:01:54
My result should be:
25-11-2011 13:41:54.
Thanks!
The DateTime. AddMinutes() method in C# is used to add the specified number of minutes to the value of this instance. It returns the new DateTime.
AddMinutes() Method in C# This method is used to return a new DateTime that adds the specified number of minutes to the value of this instance. Syntax: public DateTime AddMinutes (double value);
Add(new TimeSpan(-2,0,0)); DateTime original = new DateTime(year, month, day, 17, 30, 0); DateTime updated = original. Add(new TimeSpan(0,-45,0)); Or you can also use the DateTime. Subtract(TimeSpan) method analogously.
The AddMinutes function returns a DateTime.
DateTime.AddMinutes
Method Returns a new DateTime that adds the specified number of minutes to the value of this instance.
DateTime currentTime = DateTime.Now;
double minuts = -20;
currentTime = currentTime.AddMinutes(minuts);
Console.WriteLine("Nuværende tid: "+currentTime);
try:
currentTime = currentTime.AddMinutes(minuts);
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