Create DateTimeOffset from specified DateTime value and offset in CSharp

Description

The following code shows how to create DateTimeOffset from specified DateTime value and offset.

Example


using System;/* ww w.j a v a 2  s  . c  o m*/

public class MainClass{
  public static void Main(String[] argv){  
    DateTime localTime = new DateTime(2014, 07, 12, 06, 32, 00); 
    DateTimeOffset dateAndOffset = new DateTimeOffset(localTime, 
                             TimeZoneInfo.Local.GetUtcOffset(localTime));
    Console.WriteLine(dateAndOffset);

  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var