Normalizes the specified date time DateTimeOffset. - CSharp System

CSharp examples for System:DateTimeOffset

Description

Normalizes the specified date time DateTimeOffset.

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 ava2 s.  c  om*/

public class Main{
        /// <summary>
        /// Normalizes the specified date time.
        /// </summary>
        /// <param name="dateTime">The date time.</param>
        /// <param name="timeZone">The time zone.</param>
        /// <returns></returns>
        public static DateTimeOffset Normalize(this DateTimeOffset dateTime, TimeZoneInfo timeZone)
        {
            if (timeZone == null)
                return dateTime;
            return dateTime.ToOffset(timeZone.GetUtcOffset(dateTime));
        }
}

Related Tutorials