Creates the date time DateTimeOffset within the specified timezone - CSharp System

CSharp examples for System:DateTimeOffset

Description

Creates the date time DateTimeOffset within the specified timezone

Demo Code

// Copyright (C) 2006-2015 Esper Team. All rights reserved.                           /
using System.Text.RegularExpressions;
using System.Globalization;
using System;/*from   w  w  w  . j a  v a  2 s  . c o m*/

public class Main{
        public static DateTimeOffset CreateDateTime(
            int year,
            int month,
            int day,
            int hour,
            int minute,
            int second,
            int millisecond,
            TimeSpan offset)
        {
            return new DateTimeOffset(year, month, day, hour, minute, second, millisecond, offset);
        }
        /// <summary>
        /// Creates the date time within the specified timezone
        /// </summary>
        /// <param name="year">The year.</param>
        /// <param name="month">The month.</param>
        /// <param name="day">The day.</param>
        /// <param name="hour">The hour.</param>
        /// <param name="minute">The minute.</param>
        /// <param name="second">The second.</param>
        /// <param name="millisecond">The millisecond.</param>
        /// <param name="timeZone">The time zone.</param>
        /// <returns></returns>
        public static DateTimeOffset CreateDateTime(
            int year,
            int month,
            int day,
            int hour,
            int minute,
            int second,
            int millisecond,
            TimeZoneInfo timeZone)
        {
            var dateTimeOffset = timeZone.GetUtcOffset(new DateTime(year, month, day, hour, minute, second, millisecond));
            return new DateTimeOffset(year, month, day, hour, minute, second, millisecond, dateTimeOffset);
        }
}

Related Tutorials