DateTimeUtil.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / xsp / System / Web / Util / DateTimeUtil.cs / 1 / DateTimeUtil.cs

                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

namespace System.Web.Util { 
 
    using System;
 
    internal sealed class DateTimeUtil {
        private DateTimeUtil() {}

        const long FileTimeOffset = 504911232000000000; 
        static readonly DateTime    MinValuePlusOneDay = DateTime.MinValue.AddDays(1);
        static readonly DateTime    MaxValueMinusOneDay = DateTime.MaxValue.AddDays(-1); 
 
        static internal DateTime FromFileTimeToUtc(long filetime) {
            long universalTicks = filetime + FileTimeOffset; 

            return new DateTime(universalTicks);
        }
 
        static internal DateTime ConvertToUniversalTime(DateTime localTime) {
            if (localTime < MinValuePlusOneDay) { 
                return DateTime.MinValue; 
            }
 
            if (localTime > MaxValueMinusOneDay) {
                return DateTime.MaxValue;
            }
 
            return localTime.ToUniversalTime();
        } 
 
        static internal DateTime ConvertToLocalTime(DateTime utcTime) {
            if (utcTime < MinValuePlusOneDay) { 
                return DateTime.MinValue;
            }

            if (utcTime > MaxValueMinusOneDay) { 
                return DateTime.MaxValue;
            } 
 
            return utcTime.ToLocalTime();
        } 
    }
}

 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

namespace System.Web.Util { 
 
    using System;
 
    internal sealed class DateTimeUtil {
        private DateTimeUtil() {}

        const long FileTimeOffset = 504911232000000000; 
        static readonly DateTime    MinValuePlusOneDay = DateTime.MinValue.AddDays(1);
        static readonly DateTime    MaxValueMinusOneDay = DateTime.MaxValue.AddDays(-1); 
 
        static internal DateTime FromFileTimeToUtc(long filetime) {
            long universalTicks = filetime + FileTimeOffset; 

            return new DateTime(universalTicks);
        }
 
        static internal DateTime ConvertToUniversalTime(DateTime localTime) {
            if (localTime < MinValuePlusOneDay) { 
                return DateTime.MinValue; 
            }
 
            if (localTime > MaxValueMinusOneDay) {
                return DateTime.MaxValue;
            }
 
            return localTime.ToUniversalTime();
        } 
 
        static internal DateTime ConvertToLocalTime(DateTime utcTime) {
            if (utcTime < MinValuePlusOneDay) { 
                return DateTime.MinValue;
            }

            if (utcTime > MaxValueMinusOneDay) { 
                return DateTime.MaxValue;
            } 
 
            return utcTime.ToLocalTime();
        } 
    }
}

 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.

                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK