C# DateTime AddHours
Description
DateTime AddHours
returns a new DateTime that adds the
specified number of hours to the value of this instance.
Syntax
DateTime.AddHours
has the following syntax.
public DateTime AddHours(
double value
)
Parameters
DateTime.AddHours
has the following parameters.
value
- A number of whole and fractional hours. The value parameter can be negative or positive.
Returns
DateTime.AddHours
method returns An object whose value is the sum of the date and time represented by this instance
and the number of hours represented by value.
Example
The following example uses the AddHours method to add a number of whole and fractional values to a date and time.
It also illustrates the loss of precision caused by passing the method a value that includes a fractional component.
/*from w w w.j av a 2 s .co m*/
using System;
public class Example
{
public static void Main()
{
DateTime dateValue = new DateTime(2009, 3, 1, 12, 0, 0);
Console.WriteLine(dateValue.AddHours(1.3));
}
}
The code above generates the following result.