DateTimeUtil.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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