Compartir a través de


DateTime.AddHours Method

Adds a specified number of hours to the current DateTime object.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

Syntax

public DateTime AddHours (
         double val
)

Parameters

  • val
    A specific number of hours. Note that the number in the val parameter can be either positive or negative, and it can express partial hours as well as whole hours.

Return Value

A new DateTime object having a value that represents the sum of the current DateTime object and the specified number of hours.

Remarks

This method does not change the value of the current DateTime object; rather, it returns a new DateTime object.

The fractional part of an hour is represented by the fractional part of the val parameter (that is, anything to the right of the decimal point). For example, 4.5 is equivalent to 4 hours, 30 minutes, 0 seconds, 0 milliseconds, and 0 ticks. The number in the val parameter is rounded to the nearest tick.

Version Information

Available in the .NET Micro Framework versions 2.0, 2.5, 3.0, 4.0, 4.1, and 4.2.

See Also

Reference

DateTime Structure
DateTime Members
System Namespace