C# DateTimeOffset AddHours

Description

DateTimeOffset AddHours adds a specified number of whole and fractional hours to the current DateTimeOffset object.

Syntax

DateTimeOffset.AddHours has the following syntax.


public DateTimeOffset AddHours(
  double hours
)

Parameters

DateTimeOffset.AddHours has the following parameters.

  • hours - A number of whole and fractional hours. The number can be negative or positive.

Returns

DateTimeOffset.AddHours method returns An object whose value is the sum of the date and time represented by the current DateTimeOffset object and the number of hours represented by hours.

Example

The following example uses the AddHours method.


using System;/*from   ww  w  .j av a2  s .co m*/

public class MainClass{
  public static void Main(String[] argv){  
    DateTimeOffset startTime = new DateTimeOffset(2014, 8, 6, 0, 0, 0, 
                         DateTimeOffset.Now.Offset);
    DateTimeOffset startOfShift = startTime.AddHours(8);
    
    Console.WriteLine("Shifts for the week of {0:D}", startOfShift);
  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version