Ms的DateTime类源码

此博客为转载内容,原文链接为https://www.cnblogs.com/wannaCNBLOGS/archive/2005/08/04/207081.html ,涉及runtime相关信息技术内容。
None.gif// ==++==
None.gif
// 
None.gif
//   
None.gif
//    Copyright (c) 2002 Microsoft Corporation.  All rights reserved.
None.gif
//   
None.gif
//    The use and distribution terms for this software are contained in the file
None.gif
//    named license.txt, which can be found in the root of this distribution.
None.gif
//    By using this software in any fashion, you are agreeing to be bound by the
None.gif
//    terms of this license.
None.gif
//   
None.gif
//    You must not remove this notice, or any other, from this software.
None.gif
//   
None.gif
// 
None.gif
// ==--==
ExpandedBlockStart.gifContractedBlock.gif
namespace System dot.gif{
InBlock.gif    
InBlock.gif    
using System;
InBlock.gif    
using System.Threading;
InBlock.gif    
using System.Globalization;
InBlock.gif    
using System.Runtime.InteropServices;
InBlock.gif    
using System.Runtime.CompilerServices;
InBlock.gif    
using CultureInfo = System.Globalization.CultureInfo;
InBlock.gif    
using Calendar = System.Globalization.Calendar;
InBlock.gif
InBlock.gif    
// This value type represents a date and time.  Every DateTime 
InBlock.gif    
// object has a private field (Ticks) of type Int64 that stores the 
InBlock.gif    
// date and time as the number of 100 nanosecond intervals since 
InBlock.gif    
// 12:00 AM January 1, year 1 A.D. in the proleptic Gregorian Calendar.
InBlock.gif    
// 
InBlock.gif    
// For a description of various calendar issues, look at
InBlock.gif    
// 
InBlock.gif    
// Calendar Studies web site, at 
InBlock.gif    
// http://serendipity.nofadz.com/hermetic/cal_stud.htm.
InBlock.gif    
// 
InBlock.gif    
// 
InBlock.gif    
// Warning about 2 digit years
InBlock.gif    
// As a temporary hack until we get new DateTime <;->; String code,
InBlock.gif    
// some systems won't be able to round trip dates less than 1930.  This
InBlock.gif    
// is because we're using OleAut's string parsing routines, which look
InBlock.gif    
// at your computer's default short date string format, which uses 2 digit
InBlock.gif    
// years on most computers.  To fix this, go to Control Panel ->; Regional 
InBlock.gif    
// Settings ->; Date and change the short date style to something like
InBlock.gif    
// "M/d/yyyy" (specifying four digits for the year).
InBlock.gif    
// 
ExpandedSubBlockStart.gifContractedSubBlock.gif
    /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime"]/*' />
InBlock.gif    [Serializable()] 
InBlock.gif    [StructLayout(LayoutKind.Auto)]
InBlock.gif    
public struct DateTime : IComparable, IFormattable, IConvertible
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
// Number of 100ns ticks per time unit
InBlock.gif
        private const long TicksPerMillisecond = 10000;
InBlock.gif        
private const long TicksPerSecond = TicksPerMillisecond * 1000;
InBlock.gif        
private const long TicksPerMinute = TicksPerSecond * 60;
InBlock.gif        
private const long TicksPerHour = TicksPerMinute * 60;
InBlock.gif        
private const long TicksPerDay = TicksPerHour * 24;
InBlock.gif    
InBlock.gif        
// Number of milliseconds per time unit
InBlock.gif
        private const int MillisPerSecond = 1000;
InBlock.gif        
private const int MillisPerMinute = MillisPerSecond * 60;
InBlock.gif        
private const int MillisPerHour = MillisPerMinute * 60;
InBlock.gif        
private const int MillisPerDay = MillisPerHour * 24;
InBlock.gif    
InBlock.gif        
// Number of days in a non-leap year
InBlock.gif
        private const int DaysPerYear = 365;
InBlock.gif        
// Number of days in 4 years
InBlock.gif
        private const int DaysPer4Years = DaysPerYear * 4 + 1;
InBlock.gif        
// Number of days in 100 years
InBlock.gif
        private const int DaysPer100Years = DaysPer4Years * 25 - 1;
InBlock.gif        
// Number of days in 400 years
InBlock.gif
        private const int DaysPer400Years = DaysPer100Years * 4 + 1;
InBlock.gif    
InBlock.gif        
// Number of days from 1/1/0001 to 12/31/1600
InBlock.gif
        private const int DaysTo1601 = DaysPer400Years * 4;
InBlock.gif        
// Number of days from 1/1/0001 to 12/30/1899
InBlock.gif
        private const int DaysTo1899 = DaysPer400Years * 4 + DaysPer100Years * 3 - 367;
InBlock.gif        
// Number of days from 1/1/0001 to 12/31/9999
InBlock.gif
        private const int DaysTo10000 = DaysPer400Years * 25 - 366;
InBlock.gif    
InBlock.gif        
private const long MinTicks = 0;
InBlock.gif        
private const long MaxTicks = DaysTo10000 * TicksPerDay - 1;
InBlock.gif        
private const long MaxMillis = (long)DaysTo10000 * MillisPerDay;
InBlock.gif    
InBlock.gif        
private const long FileTimeOffset = DaysTo1601 * TicksPerDay;
InBlock.gif        
private const long DoubleDateOffset = DaysTo1899 * TicksPerDay;
InBlock.gif        
// The minimum OA date is 0100/01/01 (Note it's year 100).
InBlock.gif        
// The maximum OA date is 9999/12/31
InBlock.gif
        private const long OADateMinAsTicks = (DaysPer100Years - DaysPerYear) * TicksPerDay;
InBlock.gif        
// All OA dates must be greater than (not >=) OADateMinAsDouble
InBlock.gif
        private const double OADateMinAsDouble = -657435.0;
InBlock.gif        
// All OA dates must be less than (not <=) OADateMaxAsDouble
InBlock.gif
        private const double OADateMaxAsDouble = 2958466.0;
InBlock.gif    
InBlock.gif        
private const int DatePartYear = 0;
InBlock.gif        
private const int DatePartDayOfYear = 1;
InBlock.gif        
private const int DatePartMonth = 2;
InBlock.gif        
private const int DatePartDay = 3;
InBlock.gif    
ExpandedSubBlockStart.gifContractedSubBlock.gif        
private static readonly int[] DaysToMonth365 = dot.gif{
ExpandedSubBlockEnd.gif            
0315990120151181212243273304334365}
;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
private static readonly int[] DaysToMonth366 = dot.gif{
ExpandedSubBlockEnd.gif            
0316091121152182213244274305335366}
;
InBlock.gif    
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.MinValue"]/*' />
InBlock.gif        public static readonly DateTime MinValue = new DateTime(MinTicks);
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.MaxValue"]/*' />
InBlock.gif        public static readonly DateTime MaxValue = new DateTime(MaxTicks);
InBlock.gif            
InBlock.gif        
//
InBlock.gif        
// NOTE                     : Before the time zone is introduced, ticks is based on 1/1/0001 local time.
InBlock.gif        
// 
InBlock.gif
        private long ticks;
InBlock.gif    
InBlock.gif        
// Constructs a DateTime from a tick count. The ticks
InBlock.gif        
// argument specifies the date as the number of 100-nanosecond intervals
InBlock.gif        
// that have elapsed since 1/1/0001 12:00am.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.DateTime"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public DateTime(long ticks) dot.gif{
InBlock.gif            
if (ticks < MinTicks || ticks > MaxTicks)
InBlock.gif                
throw new ArgumentOutOfRangeException("ticks", Environment.GetResourceString("ArgumentOutOfRange_DateTimeBadTicks"));
InBlock.gif            
this.ticks = ticks;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
private DateTime(long ticksFound, int ignoreMe) dot.gif{
InBlock.gif            
this.ticks = ticksFound;
ExpandedSubBlockStart.gifContractedSubBlock.gif            
if ((ulong)ticks>(ulong)MaxTicks) dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif                
if (ticks>MaxTicks) dot.gif{
InBlock.gif                    ticks 
= MaxTicks;
ExpandedSubBlockStart.gifContractedSubBlock.gif                }
 else dot.gif{
InBlock.gif                    ticks 
= MinTicks;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Constructs a DateTime from a given year, month, and day. The
InBlock.gif        
// time-of-day of the resulting DateTime is always midnight.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.DateTime1"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public DateTime(int year, int month, int day) dot.gif{
InBlock.gif            ticks 
= DateToTicks(year, month, day);
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Constructs a DateTime from a given year, month, and day for
InBlock.gif        
// the specified calendar. The
InBlock.gif        
// time-of-day of the resulting DateTime is always midnight.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.DateTime2"]/*' />
InBlock.gif        public DateTime(int year, int month, int day, Calendar calendar) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            : 
this(year, month, day, 000, calendar) dot.gif{
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Constructs a DateTime from a given year, month, day, hour,
InBlock.gif        
// minute, and second.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.DateTime3"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public DateTime(int year, int month, int day, int hour, int minute, int second) dot.gif{
InBlock.gif            ticks 
= DateToTicks(year, month, day) + TimeToTicks(hour, minute, second);
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Constructs a DateTime from a given year, month, day, hour,
InBlock.gif        
// minute, and second for the specified calendar.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.DateTime4"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public DateTime(int year, int month, int day, int hour, int minute, int second, Calendar calendar) dot.gif{
InBlock.gif            
if (calendar == null)
InBlock.gif                
throw new ArgumentNullException("calendar");
InBlock.gif            ticks 
= calendar.ToDateTime(year, month, day, hour, minute, second, 0).Ticks;
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Constructs a DateTime from a given year, month, day, hour,
InBlock.gif        
// minute, and second.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.DateTime5"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond) dot.gif{
InBlock.gif            ticks 
= DateToTicks(year, month, day) + TimeToTicks(hour, minute, second);
ExpandedSubBlockStart.gifContractedSubBlock.gif            
if (millisecond < 0 || millisecond >= MillisPerSecond) dot.gif{
InBlock.gif                
throw new ArgumentOutOfRangeException("millisecond", String.Format(Environment.GetResourceString("ArgumentOutOfRange_Range"), 0, MillisPerSecond - 1));
ExpandedSubBlockEnd.gif            }

InBlock.gif            ticks 
+= millisecond * TicksPerMillisecond;
InBlock.gif            
if (ticks < MinTicks || ticks > MaxTicks)
InBlock.gif                
throw new ArgumentException(Environment.GetResourceString("Arg_DateTimeRange"));
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
// Constructs a DateTime from a given year, month, day, hour,
InBlock.gif        
// minute, and second for the specified calendar.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.DateTime6"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar) dot.gif{
InBlock.gif            
if (calendar == null)
InBlock.gif                
throw new ArgumentNullException("calendar");
InBlock.gif            ticks 
= calendar.ToDateTime(year, month, day, hour, minute, second, 0).Ticks;
ExpandedSubBlockStart.gifContractedSubBlock.gif            
if (millisecond < 0 || millisecond >= MillisPerSecond) dot.gif{
InBlock.gif                
throw new ArgumentOutOfRangeException("millisecond", String.Format(Environment.GetResourceString("ArgumentOutOfRange_Range"), 0, MillisPerSecond - 1));
ExpandedSubBlockEnd.gif            }
            
InBlock.gif            ticks 
+= millisecond * TicksPerMillisecond;
InBlock.gif            
if (ticks < MinTicks || ticks > MaxTicks)
InBlock.gif                
throw new ArgumentException(Environment.GetResourceString("Arg_DateTimeRange"));
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns the DateTime resulting from adding the given
InBlock.gif        
// TimeSpan to this DateTime.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.Add"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public DateTime Add(TimeSpan value) dot.gif{
InBlock.gif            
return new DateTime(ticks + value._ticks);
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns the DateTime resulting from adding a fractional number of
InBlock.gif        
// time units to this DateTime.
ExpandedSubBlockStart.gifContractedSubBlock.gif
        private DateTime Add(double value, int scale) dot.gif{
InBlock.gif            
long millis = (long)(value * scale + (value >= 0? 0.5-0.5));
InBlock.gif            
if (millis <= -MaxMillis || millis >= MaxMillis) 
InBlock.gif                
throw new ArgumentOutOfRangeException(Environment.GetResourceString("ArgumentOutOfRange_AddValue"));
InBlock.gif            
return new DateTime(ticks + millis * TicksPerMillisecond);
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns the DateTime resulting from adding a fractional number of
InBlock.gif        
// days to this DateTime. The result is computed by rounding the
InBlock.gif        
// fractional number of days given by value to the nearest
InBlock.gif        
// millisecond, and adding that interval to this DateTime. The
InBlock.gif        
// value argument is permitted to be negative.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.AddDays"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public DateTime AddDays(double value) dot.gif{
InBlock.gif            
return Add(value, MillisPerDay);
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns the DateTime resulting from adding a fractional number of
InBlock.gif        
// hours to this DateTime. The result is computed by rounding the
InBlock.gif        
// fractional number of hours given by value to the nearest
InBlock.gif        
// millisecond, and adding that interval to this DateTime. The
InBlock.gif        
// value argument is permitted to be negative.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.AddHours"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public DateTime AddHours(double value) dot.gif{
InBlock.gif            
return Add(value, MillisPerHour);
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns the DateTime resulting from the given number of
InBlock.gif        
// milliseconds to this DateTime. The result is computed by rounding
InBlock.gif        
// the number of milliseconds given by value to the nearest integer,
InBlock.gif        
// and adding that interval to this DateTime. The value
InBlock.gif        
// argument is permitted to be negative.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.AddMilliseconds"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public DateTime AddMilliseconds(double value) dot.gif{
InBlock.gif            
return Add(value, 1);
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns the DateTime resulting from adding a fractional number of
InBlock.gif        
// minutes to this DateTime. The result is computed by rounding the
InBlock.gif        
// fractional number of minutes given by value to the nearest
InBlock.gif        
// millisecond, and adding that interval to this DateTime. The
InBlock.gif        
// value argument is permitted to be negative.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.AddMinutes"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public DateTime AddMinutes(double value) dot.gif{
InBlock.gif            
return Add(value, MillisPerMinute);
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns the DateTime resulting from adding the given number of
InBlock.gif        
// months to this DateTime. The result is computed by incrementing
InBlock.gif        
// (or decrementing) the year and month parts of this DateTime by
InBlock.gif        
// months months, and, if required, adjusting the day part of the
InBlock.gif        
// resulting date downwards to the last day of the resulting month in the
InBlock.gif        
// resulting year. The time-of-day part of the result is the same as the
InBlock.gif        
// time-of-day part of this DateTime.
InBlock.gif        
//
InBlock.gif        
// In more precise terms, considering this DateTime to be of the
InBlock.gif        
// form y / m / d + t, where y is the
InBlock.gif        
// year, m is the month, d is the day, and t is the
InBlock.gif        
// time-of-day, the result is y1 / m1 / d1 + t,
InBlock.gif        
// where y1 and m1 are computed by adding months months
InBlock.gif        
// to y and m, and d1 is the largest value less than
InBlock.gif        
// or equal to d that denotes a valid day in month m1 of year
InBlock.gif        
// y1.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.AddMonths"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public DateTime AddMonths(int months) dot.gif{
InBlock.gif            
if (months < -120000 || months > 120000throw new ArgumentOutOfRangeException("months", Environment.GetResourceString("ArgumentOutOfRange_DateTimeBadMonths"));
InBlock.gif            
int y = GetDatePart(DatePartYear);
InBlock.gif            
int m = GetDatePart(DatePartMonth);
InBlock.gif            
int d = GetDatePart(DatePartDay);
InBlock.gif            
int i = m - 1 + months;
ExpandedSubBlockStart.gifContractedSubBlock.gif            
if (i >= 0dot.gif{
InBlock.gif                m 
= i % 12 + 1;
InBlock.gif                y 
= y + i / 12;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockStart.gifContractedSubBlock.gif            
else dot.gif{
InBlock.gif                m 
= 12 + (i + 1% 12;
InBlock.gif                y 
= y + (i - 11/ 12;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
int days = DaysInMonth(y, m);
InBlock.gif            
if (d > days) d = days;
InBlock.gif            
return new DateTime(DateToTicks(y, m, d) + ticks % TicksPerDay);
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns the DateTime resulting from adding a fractional number of
InBlock.gif        
// seconds to this DateTime. The result is computed by rounding the
InBlock.gif        
// fractional number of seconds given by value to the nearest
InBlock.gif        
// millisecond, and adding that interval to this DateTime. The
InBlock.gif        
// value argument is permitted to be negative.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.AddSeconds"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public DateTime AddSeconds(double value) dot.gif{
InBlock.gif            
return Add(value, MillisPerSecond);
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns the DateTime resulting from adding the given number of
InBlock.gif        
// 100-nanosecond ticks to this DateTime. The value argument
InBlock.gif        
// is permitted to be negative.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.AddTicks"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public DateTime AddTicks(long value) dot.gif{
InBlock.gif            
return new DateTime(ticks + value);
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns the DateTime resulting from adding the given number of
InBlock.gif        
// years to this DateTime. The result is computed by incrementing
InBlock.gif        
// (or decrementing) the year part of this DateTime by value
InBlock.gif        
// years. If the month and day of this DateTime is 2/29, and if the
InBlock.gif        
// resulting year is not a leap year, the month and day of the resulting
InBlock.gif        
// DateTime becomes 2/28. Otherwise, the month, day, and time-of-day
InBlock.gif        
// parts of the result are the same as those of this DateTime.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.AddYears"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public DateTime AddYears(int value) dot.gif{
InBlock.gif            
return AddMonths(value * 12);
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
InBlock.gif    
InBlock.gif        
// Compares two DateTime values, returning an integer that indicates
InBlock.gif        
// their relationship.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.Compare"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public static int Compare(DateTime t1, DateTime t2) dot.gif{
InBlock.gif            
if (t1.ticks > t2.ticks) return 1;
InBlock.gif            
if (t1.ticks < t2.ticks) return -1;
InBlock.gif            
return 0;
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Compares this DateTime to a given object. This method provides an
InBlock.gif        
// implementation of the IComparable interface. The object
InBlock.gif        
// argument must be another DateTime, or otherwise an exception
InBlock.gif        
// occurs.  Null is considered less than any instance.
InBlock.gif        
//
InBlock.gif        
// Returns a value less than zero if this  object
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.CompareTo"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public int CompareTo(Object value) dot.gif{
InBlock.gif            
if (value == nullreturn 1;
ExpandedSubBlockStart.gifContractedSubBlock.gif            
if (!(value is DateTime)) dot.gif{
InBlock.gif                
throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDateTime"));
ExpandedSubBlockEnd.gif            }

InBlock.gif    
InBlock.gif            
long t = ((DateTime)value).ticks;
InBlock.gif            
if (ticks > t) return 1;
InBlock.gif            
if (ticks < t) return -1;
InBlock.gif            
return 0;
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns the tick count corresponding to the given year, month, and day.
InBlock.gif        
// Will check the if the parameters are valid.
ExpandedSubBlockStart.gifContractedSubBlock.gif
        private static long DateToTicks(int year, int month, int day) dot.gif{     
ExpandedSubBlockStart.gifContractedSubBlock.gif            
if (year >= 1 && year <= 9999 && month >= 1 && month <= 12dot.gif{
InBlock.gif                
int[] days = IsLeapYear(year)? DaysToMonth366: DaysToMonth365;
ExpandedSubBlockStart.gifContractedSubBlock.gif                
if (day >= 1 && day <= days[month] - days[month - 1]) dot.gif{
InBlock.gif                    
int y = year - 1;
InBlock.gif                    
int n = y * 365 + y / 4 - y / 100 + y / 400 + days[month - 1+ day - 1;
InBlock.gif                    
return n * TicksPerDay;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
throw new ArgumentOutOfRangeException(Environment.GetResourceString("ArgumentOutOfRange_BadYearMonthDay"));
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Return the tick count corresponding to the given hour, minute, second.
InBlock.gif        
// Will check the if the parameters are valid.
InBlock.gif
        private static long TimeToTicks(int hour, int minute, int second)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//TimeSpan.TimeToTicks is a family access function which does no error checking, so
InBlock.gif            
//we need to put some error checking out here.
InBlock.gif
            if (hour >= 0 && hour < 24 && minute >= 0 && minute < 60 && second >=0 && second < 60)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return (TimeSpan.TimeToTicks(hour, minute, second));
ExpandedSubBlockEnd.gif            }

InBlock.gif            
throw new ArgumentOutOfRangeException(Environment.GetResourceString("ArgumentOutOfRange_BadHourMinuteSecond"));
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns the number of days in the month given by the year and
InBlock.gif        
// month arguments.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.DaysInMonth"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public static int DaysInMonth(int year, int month) dot.gif{
InBlock.gif            
if (month < 1 || month > 12throw new ArgumentOutOfRangeException(Environment.GetResourceString("ArgumentOutOfRange_Month"));
InBlock.gif            
int[] days = IsLeapYear(year)? DaysToMonth366: DaysToMonth365;
InBlock.gif            
return days[month] - days[month - 1];
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
// Converts an OLE Date to a tick count.
InBlock.gif        
// This function is duplicated in COMDateTime.cpp
ExpandedSubBlockStart.gifContractedSubBlock.gif
        internal static long DoubleDateToTicks(double value) dot.gif{
InBlock.gif            
if (value >= OADateMaxAsDouble || value <= OADateMinAsDouble)
InBlock.gif                
throw new ArgumentException(Environment.GetResourceString("Arg_OleAutDateInvalid"));
InBlock.gif            
long millis = (long)(value * MillisPerDay + (value >= 0? 0.5-0.5));
InBlock.gif            
// The interesting thing here is when you have a value like 12.5 it all positive 12 days and 12 hours from 01/01/1899
InBlock.gif            
// However if you a value of -12.25 it is minus 12 days but still positive 6 hours, almost as though you meant -11.75 all negative
InBlock.gif            
// This line below fixes up the millis in the negative case
ExpandedSubBlockStart.gifContractedSubBlock.gif
            if (millis < 0dot.gif{
InBlock.gif                millis 
-= (millis % MillisPerDay) * 2;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
InBlock.gif            millis 
+= DoubleDateOffset / TicksPerMillisecond;
InBlock.gif
InBlock.gif            
if (millis < 0 || millis >= MaxMillis) throw new ArgumentException(Environment.GetResourceString("Arg_OleAutDateScale"));
InBlock.gif            
return millis * TicksPerMillisecond;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
// Checks if this DateTime is equal to a given object. Returns
InBlock.gif        
// true if the given object is a boxed DateTime and its value
InBlock.gif        
// is equal to the value of this DateTime. Returns false
InBlock.gif        
// otherwise.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.Equals"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public override bool Equals(Object value) dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
if (value is DateTime) dot.gif{
InBlock.gif                
return ticks == ((DateTime)value).ticks;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return false;
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Compares two DateTime values for equality. Returns true if
InBlock.gif        
// the two DateTime values are equal, or false if they are
InBlock.gif        
// not equal.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.Equals1"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public static bool Equals(DateTime t1, DateTime t2) dot.gif{
InBlock.gif            
return t1.ticks == t2.ticks;
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Creates a DateTime from a Windows filetime. A Windows filetime is
InBlock.gif        
// a long representing the date and time as the number of
InBlock.gif        
// 100-nanosecond intervals that have elapsed since 1/1/1601 12:00am.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.FromFileTime"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public static DateTime FromFileTime(long fileTime) dot.gif{
InBlock.gif            
if (fileTime < 0)
InBlock.gif                
throw new ArgumentOutOfRangeException(Environment.GetResourceString("ArgumentOutOfRange_FileTimeInvalid"));
InBlock.gif
InBlock.gif            
// This is the ticks in Universal time for this fileTime.
InBlock.gif
            long universalTicks = fileTime + FileTimeOffset;
InBlock.gif
InBlock.gif            
InBlock.gif            
//We do the next operations in ticks instead of taking advantage of the TimeSpan/DateTime
InBlock.gif            
//operators because the DateTime constructor which takes two parameters silently deals
InBlock.gif            
//properly with overflows by rounding to max value or minvalue.  The publicly exposed
InBlock.gif            
//constructors throw an exception.
InBlock.gif
            DateTime univDT = new DateTime(universalTicks);
InBlock.gif            
// We can safely cast TimeZone.CurrentTimeZone to CurrentSystemTimeZone since CurrentTimeZone is a static method in TimeZone class.
InBlock.gif
            CurrentSystemTimeZone tz = (CurrentSystemTimeZone)TimeZone.CurrentTimeZone;
InBlock.gif            
long localTicks = universalTicks + tz.GetUtcOffsetFromUniversalTime(univDT);
InBlock.gif            
return new DateTime(localTicks, 0);
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Creates a DateTime from an OLE Automation Date.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.FromOADate"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public static DateTime FromOADate(double d) dot.gif{
InBlock.gif            
return new DateTime(DoubleDateToTicks(d));
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns the date part of this DateTime. The resulting value
InBlock.gif        
// corresponds to this DateTime with the time-of-day part set to
InBlock.gif        
// zero (midnight).
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.Date"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public DateTime Date dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn new DateTime(ticks - ticks % TicksPerDay); }
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns a given date part of this DateTime. This method is used
InBlock.gif        
// to compute the year, day-of-year, month, or day part.
ExpandedSubBlockStart.gifContractedSubBlock.gif
        private int GetDatePart(int part) dot.gif{
InBlock.gif            
// n = number of days since 1/1/0001
InBlock.gif
            int n = (int)(ticks / TicksPerDay);
InBlock.gif            
// y400 = number of whole 400-year periods since 1/1/0001
InBlock.gif
            int y400 = n / DaysPer400Years;
InBlock.gif            
// n = day number within 400-year period
InBlock.gif
            n -= y400 * DaysPer400Years;
InBlock.gif            
// y100 = number of whole 100-year periods within 400-year period
InBlock.gif
            int y100 = n / DaysPer100Years;
InBlock.gif            
// Last 100-year period has an extra day, so decrement result if 4
InBlock.gif
            if (y100 == 4) y100 = 3;
InBlock.gif            
// n = day number within 100-year period
InBlock.gif
            n -= y100 * DaysPer100Years;
InBlock.gif            
// y4 = number of whole 4-year periods within 100-year period
InBlock.gif
            int y4 = n / DaysPer4Years;
InBlock.gif            
// n = day number within 4-year period
InBlock.gif
            n -= y4 * DaysPer4Years;
InBlock.gif            
// y1 = number of whole years within 4-year period
InBlock.gif
            int y1 = n / DaysPerYear;
InBlock.gif            
// Last year has an extra day, so decrement result if 4
InBlock.gif
            if (y1 == 4) y1 = 3;
InBlock.gif            
// If year was requested, compute and return it
ExpandedSubBlockStart.gifContractedSubBlock.gif
            if (part == DatePartYear) dot.gif{
InBlock.gif                
return y400 * 400 + y100 * 100 + y4 * 4 + y1 + 1;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
// n = day number within year
InBlock.gif
            n -= y1 * DaysPerYear;
InBlock.gif            
// If day-of-year was requested, return it
InBlock.gif
            if (part == DatePartDayOfYear) return n + 1;
InBlock.gif            
// Leap year calculation looks different from IsLeapYear since y1, y4,
InBlock.gif            
// and y100 are relative to year 1, not year 0
InBlock.gif
            bool leapYear = y1 == 3 && (y4 != 24 || y100 == 3);
InBlock.gif            
int[] days = leapYear? DaysToMonth366: DaysToMonth365;
InBlock.gif            
// All months have less than 32 days, so n >> 5 is a good conservative
InBlock.gif            
// estimate for the month
InBlock.gif
            int m = n >> 5 + 1;
InBlock.gif            
// m = 1-based month number
InBlock.gif
            while (n >= days[m]) m++;
InBlock.gif            
// If month was requested, return it
InBlock.gif
            if (part == DatePartMonth) return m;
InBlock.gif            
// Return 1-based day-of-month
InBlock.gif
            return n - days[m - 1+ 1;
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns the day-of-month part of this DateTime. The returned
InBlock.gif        
// value is an integer between 1 and 31.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.Day"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public int Day dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn GetDatePart(DatePartDay); }
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns the day-of-week part of this DateTime. The returned value
InBlock.gif        
// is an integer between 0 and 6, where 0 indicates Sunday, 1 indicates
InBlock.gif        
// Monday, 2 indicates Tuesday, 3 indicates Wednesday, 4 indicates
InBlock.gif        
// Thursday, 5 indicates Friday, and 6 indicates Saturday.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.DayOfWeek"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public DayOfWeek DayOfWeek dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn (DayOfWeek)((ticks / TicksPerDay + 1% 7); }
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns the day-of-year part of this DateTime. The returned value
InBlock.gif        
// is an integer between 1 and 366.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.DayOfYear"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public int DayOfYear dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn GetDatePart(DatePartDayOfYear); }
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns the hash code for this DateTime.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.GetHashCode"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public override int GetHashCode() dot.gif{
InBlock.gif            
return (int)ticks ^ (int)(ticks >> 32);
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns the hour part of this DateTime. The returned value is an
InBlock.gif        
// integer between 0 and 23.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.Hour"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public int Hour dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn (int)((ticks / TicksPerHour) % 24); }
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns the millisecond part of this DateTime. The returned value
InBlock.gif        
// is an integer between 0 and 999.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.Millisecond"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public int Millisecond dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn (int)((ticks / TicksPerMillisecond) % 1000); }
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns the minute part of this DateTime. The returned value is
InBlock.gif        
// an integer between 0 and 59.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.Minute"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public int Minute dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn (int)((ticks / TicksPerMinute) % 60); }
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns the month part of this DateTime. The returned value is an
InBlock.gif        
// integer between 1 and 12.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.Month"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public int Month dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn GetDatePart(DatePartMonth); }
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns a DateTime representing the current date and time. The
InBlock.gif        
// resolution of the returned value depends on the system timer. For
InBlock.gif        
// Windows NT 3.5 and later the timer resolution is approximately 10ms,
InBlock.gif        
// for Windows NT 3.1 it is approximately 16ms, and for Windows 95 and 98
InBlock.gif        
// it is approximately 55ms.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.Now"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public static DateTime Now dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn new DateTime(GetSystemFileTime() + FileTimeOffset); }
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.UtcNow"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public static DateTime UtcNow dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gif
InBlock.gif                
return DateTime.Now.ToUniversalTime();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns the second part of this DateTime. The returned value is
InBlock.gif        
// an integer between 0 and 59.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.Second"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public int Second dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn (int)((ticks / TicksPerSecond) % 60); }
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns the current date and time in Windows filetime format.
InBlock.gif
        [MethodImplAttribute(MethodImplOptions.InternalCall)]
InBlock.gif        
private static extern long GetSystemFileTime();
InBlock.gif    
InBlock.gif        
// Returns the tick count for this DateTime. The returned value is
InBlock.gif        
// the number of 100-nanosecond intervals that have elapsed since 1/1/0001
InBlock.gif        
// 12:00am.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.Ticks"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public long Ticks dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn ticks; }
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns the time-of-day part of this DateTime. The returned value
InBlock.gif        
// is a TimeSpan that indicates the time elapsed since midnight.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.TimeOfDay"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public TimeSpan TimeOfDay dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn new TimeSpan(ticks % TicksPerDay); }
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns a DateTime representing the current date. The date part
InBlock.gif        
// of the returned value is the current date, and the time-of-day part of
InBlock.gif        
// the returned value is zero (midnight).
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.Today"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public static DateTime Today dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gif{
InBlock.gif                
long ticks = GetSystemFileTime() + FileTimeOffset;
InBlock.gif                
return new DateTime(ticks - ticks % TicksPerDay);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Returns the year part of this DateTime. The returned value is an
InBlock.gif        
// integer between 1 and 9999.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.Year"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public int Year dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn GetDatePart(DatePartYear); }
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Checks whether a given year is a leap year. This method returns true if
InBlock.gif        
// year is a leap year, or false if not.
InBlock.gif        
//
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.IsLeapYear"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public static bool IsLeapYear(int year) dot.gif{
InBlock.gif            
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Constructs a DateTime from a string. The string must specify a
InBlock.gif        
// date and optionally a time in a culture-specific or universal format.
InBlock.gif        
// Leading and trailing whitespace characters are allowed.
InBlock.gif        
// 
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.Parse"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public static DateTime Parse(String s) dot.gif{
InBlock.gif            
return (Parse(s, null));
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Constructs a DateTime from a string. The string must specify a
InBlock.gif        
// date and optionally a time in a culture-specific or universal format.
InBlock.gif        
// Leading and trailing whitespace characters are allowed.
InBlock.gif        
// 
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.Parse1"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public static DateTime Parse(String s, IFormatProvider provider) dot.gif{
InBlock.gif            
return (Parse(s, provider, DateTimeStyles.None));
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.Parse2"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public static DateTime Parse(String s, IFormatProvider provider, DateTimeStyles styles) dot.gif{
InBlock.gif            
return (DateTimeParse.Parse(s, DateTimeFormatInfo.GetInstance(provider), styles));
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
// Constructs a DateTime from a string. The string must specify a
InBlock.gif        
// date and optionally a time in a culture-specific or universal format.
InBlock.gif        
// Leading and trailing whitespace characters are allowed.
InBlock.gif        
// 
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.ParseExact"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public static DateTime ParseExact(String s, String format, IFormatProvider provider) dot.gif{
InBlock.gif            
return (DateTimeParse.ParseExact(s, format, DateTimeFormatInfo.GetInstance(provider), DateTimeStyles.None));
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
// Constructs a DateTime from a string. The string must specify a
InBlock.gif        
// date and optionally a time in a culture-specific or universal format.
InBlock.gif        
// Leading and trailing whitespace characters are allowed.
InBlock.gif        
// 
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.ParseExact1"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public static DateTime ParseExact(String s, String format, IFormatProvider provider, DateTimeStyles style) dot.gif{
InBlock.gif            
return (DateTimeParse.ParseExact(s, format, DateTimeFormatInfo.GetInstance(provider), style));
ExpandedSubBlockEnd.gif        }
    
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.ParseExact2"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public static DateTime ParseExact(String s, String[] formats, IFormatProvider provider, DateTimeStyles style) dot.gif{
InBlock.gif            DateTime result;
ExpandedSubBlockStart.gifContractedSubBlock.gif            
if (!DateTimeParse.ParseExactMultiple(s, formats, DateTimeFormatInfo.GetInstance(provider), style, out result)) dot.gif{
InBlock.gif                
//
InBlock.gif                
// We can not parse successfully in any of the format provided.
InBlock.gif                
//
InBlock.gif
                throw new FormatException(Environment.GetResourceString("Format_BadDateTime"));
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return (result);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.Subtract"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public TimeSpan Subtract(DateTime value) dot.gif{
InBlock.gif            
return new TimeSpan(ticks - value.ticks);
ExpandedSubBlockEnd.gif        }

InBlock.gif    
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.Subtract1"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public DateTime Subtract(TimeSpan value) dot.gif{
InBlock.gif            
return new DateTime(ticks - value._ticks);
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// This function is duplicated in COMDateTime.cpp
ExpandedSubBlockStart.gifContractedSubBlock.gif
        private static double TicksToOADate(long value) dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
/**//////////////////////////////////////////////////////////////
InBlock.gif            
/////////////////////////////////////////////////////////////
InBlock.gif            
/////////////// HACK HACK HACK HACK
InBlock.gif            
/// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.TicksToLocal"]/*' />
InBlock.gif            
/////////////////////////////////////////////////////////////
ExpandedSubBlockEnd.gif            
/////////////////////////////////////////////////////////////

InBlock.gif            if (value == 0)
InBlock.gif                
return 0.0;  // Returns OleAut's zero'ed date value.
InBlock.gif
            if (value < TicksPerDay) // This is a fix for VB. They want the default day to be 1/1/0001 rathar then 12/30/1899.
InBlock.gif
                value += DoubleDateOffset; // We could have moved this fix down but we would like to keep the bounds check.
InBlock.gif
            if (value < OADateMinAsTicks)
InBlock.gif                
throw new OverflowException(Environment.GetResourceString("Arg_OleAutDateInvalid"));
InBlock.gif            
// Currently, our max date == OA's max date (12/31/9999), so we don't 
InBlock.gif            
// need an overflow check in that direction.
InBlock.gif
            long millis = (value  - DoubleDateOffset) / TicksPerMillisecond;
ExpandedSubBlockStart.gifContractedSubBlock.gif            
if (millis < 0dot.gif{
InBlock.gif                
long frac = millis % MillisPerDay;
InBlock.gif                
if (frac != 0) millis -= (MillisPerDay + frac) * 2;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return (double)millis / MillisPerDay;
ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif        
// Converts the DateTime instance into an OLE Automation compatible
InBlock.gif        
// double date.
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.ToOADate"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public double ToOADate() dot.gif{
InBlock.gif            
return TicksToOADate(ticks);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.ToFileTime"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public long ToFileTime() dot.gif{
InBlock.gif            
// We must convert the current time to UTC time, but we can't call
InBlock.gif            
// ToUniversalTime here since we could get something that overflows
InBlock.gif            
// DateTime.MaxValue.
InBlock.gif
            long t = this.ticks - FileTimeOffset;
InBlock.gif            
// Convert to universal time
InBlock.gif
            t -= TimeZone.CurrentTimeZone.GetUtcOffset(this).Ticks;
InBlock.gif
InBlock.gif            
if (t < 0throw new ArgumentOutOfRangeException(Environment.GetResourceString("ArgumentOutOfRange_FileTimeInvalid"));
InBlock.gif            
return t;
ExpandedSubBlockEnd.gif        }

InBlock.gif    
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.ToLocalTime"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public DateTime ToLocalTime() dot.gif{
InBlock.gif            
return TimeZone.CurrentTimeZone.ToLocalTime(this);
ExpandedSubBlockEnd.gif        }

InBlock.gif    
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.ToLongDateString"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public String ToLongDateString() dot.gif{
InBlock.gif            
return (ToString("D"null));
ExpandedSubBlockEnd.gif        }

InBlock.gif    
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.ToLongTimeString"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public String ToLongTimeString() dot.gif{
InBlock.gif            
return (ToString("T"null));
ExpandedSubBlockEnd.gif        }

InBlock.gif    
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.ToShortDateString"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public String ToShortDateString() dot.gif{
InBlock.gif            
return (ToString("d"null));
ExpandedSubBlockEnd.gif        }

InBlock.gif    
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.ToShortTimeString"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public String ToShortTimeString() dot.gif{
InBlock.gif            
return (ToString("t"null));
ExpandedSubBlockEnd.gif        }

InBlock.gif    
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.ToString"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public override String ToString() dot.gif{
InBlock.gif            
return ToString(nullnull); 
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.ToString3"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public String ToString(String format) dot.gif{
InBlock.gif            
return ToString(format, null);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.ToString1"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public String ToString(IFormatProvider provider) dot.gif{
InBlock.gif            
return (ToString(null, provider)); 
ExpandedSubBlockEnd.gif        }

InBlock.gif         
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.ToString2"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public String ToString(String format, IFormatProvider provider) dot.gif{
InBlock.gif            
return (DateTimeFormat.Format(this
InBlock.gif                format, DateTimeFormatInfo.GetInstance(provider)));
ExpandedSubBlockEnd.gif        }

InBlock.gif    
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.ToUniversalTime"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public DateTime ToUniversalTime() dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
try dot.gif
InBlock.gif                
return TimeZone.CurrentTimeZone.ToUniversalTime(this);
ExpandedSubBlockStart.gifContractedSubBlock.gif            }
 catch (Exception) dot.gif{
InBlock.gif                
long tickCount = this.ticks - TimeZone.CurrentTimeZone.GetUtcOffset(this).Ticks;
ExpandedSubBlockStart.gifContractedSubBlock.gif                
if (tickCount>MaxTicks) dot.gif{
InBlock.gif                    
return new DateTime(MaxTicks);
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockStart.gifContractedSubBlock.gif                
if (tickCount<MinTicks) dot.gif{
InBlock.gif                    
return new DateTime(MinTicks);
ExpandedSubBlockEnd.gif                }

InBlock.gif                
throw;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif            
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.operatorADD"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public static DateTime operator +(DateTime d, TimeSpan t) dot.gif{
InBlock.gif            
return new DateTime(d.ticks + t._ticks);
ExpandedSubBlockEnd.gif        }

InBlock.gif    
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.operatorSUB"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public static DateTime operator -(DateTime d, TimeSpan t) dot.gif{
InBlock.gif            
return new DateTime(d.ticks - t._ticks);
ExpandedSubBlockEnd.gif        }

InBlock.gif    
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.operatorSUB1"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public static TimeSpan operator -(DateTime d1, DateTime d2) dot.gif{
InBlock.gif            
return new TimeSpan(d1.ticks - d2.ticks);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.operatorEQ"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public static bool operator ==(DateTime d1, DateTime d2) dot.gif{
InBlock.gif            
return d1.ticks == d2.ticks;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.operatorNE"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public static bool operator !=(DateTime d1, DateTime d2) dot.gif{
InBlock.gif            
return d1.ticks != d2.ticks;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.operatorLT"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public static bool operator <(DateTime t1, DateTime t2) dot.gif{
InBlock.gif            
return t1.ticks < t2.ticks;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.operatorLE"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public static bool operator <=(DateTime t1, DateTime t2) dot.gif{
InBlock.gif            
return t1.ticks <= t2.ticks;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.operatorGT"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public static bool operator >(DateTime t1, DateTime t2) dot.gif{
InBlock.gif            
return t1.ticks > t2.ticks;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.operatorGE"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public static bool operator >=(DateTime t1, DateTime t2) dot.gif{
InBlock.gif            
return t1.ticks >= t2.ticks;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
InBlock.gif        
// Returns a string array containing all of the known date and time options for the 
InBlock.gif        
// current culture.  The strings returned are properly formatted date and 
InBlock.gif        
// time strings for the current instance of DateTime.
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.GetDateTimeFormats"]/*' />
InBlock.gif        public String[] GetDateTimeFormats()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return (GetDateTimeFormats(CultureInfo.CurrentCulture));
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
// Returns a string array containing all of the known date and time options for the 
InBlock.gif        
// using the information provided by IFormatProvider.  The strings returned are properly formatted date and 
InBlock.gif        
// time strings for the current instance of DateTime.
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.GetDateTimeFormats1"]/*' />
InBlock.gif        public String[] GetDateTimeFormats(IFormatProvider provider)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return (DateTimeFormat.GetAllDateTimes(this, DateTimeFormatInfo.GetInstance(provider)));
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif    
InBlock.gif        
// Returns a string array containing all of the date and time options for the 
InBlock.gif        
// given format format and current culture.  The strings returned are properly formatted date and 
InBlock.gif        
// time strings for the current instance of DateTime.
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.GetDateTimeFormats2"]/*' />
InBlock.gif        public String[] GetDateTimeFormats(char format)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return (GetDateTimeFormats(format, CultureInfo.CurrentCulture));
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
// Returns a string array containing all of the date and time options for the 
InBlock.gif        
// given format format and given culture.  The strings returned are properly formatted date and 
InBlock.gif        
// time strings for the current instance of DateTime.
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.GetDateTimeFormats3"]/*' />
InBlock.gif        public String[] GetDateTimeFormats(char format, IFormatProvider provider)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return (DateTimeFormat.GetAllDateTimes(this, format, DateTimeFormatInfo.GetInstance(provider)));
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
//
InBlock.gif        
// IValue implementation
InBlock.gif        
// 
InBlock.gif
        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.GetTypeCode"]/*' />
ExpandedSubBlockStart.gifContractedSubBlock.gif        public TypeCode GetTypeCode() dot.gif{
InBlock.gif            
return TypeCode.DateTime;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.IConvertible.ToBoolean"]/*' />
ExpandedSubBlockEnd.gif        
/// <internalonly/>

ExpandedSubBlockStart.gifContractedSubBlock.gif        bool IConvertible.ToBoolean(IFormatProvider provider) dot.gif{
InBlock.gif            
throw new InvalidCastException(String.Format(Environment.GetResourceString("InvalidCast_FromTo"), "DateTime""Boolean"));
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.IConvertible.ToChar"]/*' />
ExpandedSubBlockEnd.gif        
/// <internalonly/>

ExpandedSubBlockStart.gifContractedSubBlock.gif        char IConvertible.ToChar(IFormatProvider provider) dot.gif{
InBlock.gif            
throw new InvalidCastException(String.Format(Environment.GetResourceString("InvalidCast_FromTo"), "DateTime""Char"));
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.IConvertible.ToSByte"]/*' />
ExpandedSubBlockEnd.gif        
/// <internalonly/>

InBlock.gif        [CLSCompliant(false)]
ExpandedSubBlockStart.gifContractedSubBlock.gif        
sbyte IConvertible.ToSByte(IFormatProvider provider) dot.gif{
InBlock.gif            
throw new InvalidCastException(String.Format(Environment.GetResourceString("InvalidCast_FromTo"), "DateTime""SByte"));
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.IConvertible.ToByte"]/*' />
ExpandedSubBlockEnd.gif        
/// <internalonly/>

ExpandedSubBlockStart.gifContractedSubBlock.gif        byte IConvertible.ToByte(IFormatProvider provider) dot.gif{
InBlock.gif            
throw new InvalidCastException(String.Format(Environment.GetResourceString("InvalidCast_FromTo"), "DateTime""Byte"));
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.IConvertible.ToInt16"]/*' />
ExpandedSubBlockEnd.gif        
/// <internalonly/>

ExpandedSubBlockStart.gifContractedSubBlock.gif        short IConvertible.ToInt16(IFormatProvider provider) dot.gif{
InBlock.gif            
throw new InvalidCastException(String.Format(Environment.GetResourceString("InvalidCast_FromTo"), "DateTime""Int16"));
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.IConvertible.ToUInt16"]/*' />
ExpandedSubBlockEnd.gif        
/// <internalonly/>

InBlock.gif        [CLSCompliant(false)]
ExpandedSubBlockStart.gifContractedSubBlock.gif        
ushort IConvertible.ToUInt16(IFormatProvider provider) dot.gif{
InBlock.gif            
throw new InvalidCastException(String.Format(Environment.GetResourceString("InvalidCast_FromTo"), "DateTime""UInt16"));
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.IConvertible.ToInt32"]/*' />
ExpandedSubBlockEnd.gif        
/// <internalonly/>

ExpandedSubBlockStart.gifContractedSubBlock.gif        int IConvertible.ToInt32(IFormatProvider provider) dot.gif{
InBlock.gif            
throw new InvalidCastException(String.Format(Environment.GetResourceString("InvalidCast_FromTo"), "DateTime""Int32"));
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.IConvertible.ToUInt32"]/*' />
ExpandedSubBlockEnd.gif        
/// <internalonly/>

InBlock.gif        [CLSCompliant(false)]
ExpandedSubBlockStart.gifContractedSubBlock.gif        
uint IConvertible.ToUInt32(IFormatProvider provider) dot.gif{
InBlock.gif            
throw new InvalidCastException(String.Format(Environment.GetResourceString("InvalidCast_FromTo"), "DateTime""UInt32"));
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.IConvertible.ToInt64"]/*' />
ExpandedSubBlockEnd.gif        
/// <internalonly/>

ExpandedSubBlockStart.gifContractedSubBlock.gif        long IConvertible.ToInt64(IFormatProvider provider) dot.gif{
InBlock.gif            
throw new InvalidCastException(String.Format(Environment.GetResourceString("InvalidCast_FromTo"), "DateTime""Int64"));
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.IConvertible.ToUInt64"]/*' />
ExpandedSubBlockEnd.gif        
/// <internalonly/>

InBlock.gif        [CLSCompliant(false)]
ExpandedSubBlockStart.gifContractedSubBlock.gif        
ulong IConvertible.ToUInt64(IFormatProvider provider) dot.gif{
InBlock.gif            
throw new InvalidCastException(String.Format(Environment.GetResourceString("InvalidCast_FromTo"), "DateTime""UInt64"));
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.IConvertible.ToSingle"]/*' />
ExpandedSubBlockEnd.gif        
/// <internalonly/>

ExpandedSubBlockStart.gifContractedSubBlock.gif        float IConvertible.ToSingle(IFormatProvider provider) dot.gif{
InBlock.gif            
throw new InvalidCastException(String.Format(Environment.GetResourceString("InvalidCast_FromTo"), "DateTime""Single"));
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.IConvertible.ToDouble"]/*' />
ExpandedSubBlockEnd.gif        
/// <internalonly/>

ExpandedSubBlockStart.gifContractedSubBlock.gif        double IConvertible.ToDouble(IFormatProvider provider) dot.gif{
InBlock.gif            
throw new InvalidCastException(String.Format(Environment.GetResourceString("InvalidCast_FromTo"), "DateTime""Double"));
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.IConvertible.ToDecimal"]/*' />
ExpandedSubBlockEnd.gif        
/// <internalonly/>

ExpandedSubBlockStart.gifContractedSubBlock.gif        Decimal IConvertible.ToDecimal(IFormatProvider provider) dot.gif{
InBlock.gif            
throw new InvalidCastException(String.Format(Environment.GetResourceString("InvalidCast_FromTo"), "DateTime""Decimal"));
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.IConvertible.ToDateTime"]/*' />
ExpandedSubBlockEnd.gif        
/// <internalonly/>

ExpandedSubBlockStart.gifContractedSubBlock.gif        DateTime IConvertible.ToDateTime(IFormatProvider provider) dot.gif{
InBlock.gif            
return this;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <include file='doc\DateTime.uex' path='docs/doc[@for="DateTime.IConvertible.ToType"]/*' />
ExpandedSubBlockEnd.gif        
/// <internalonly/>

ExpandedSubBlockStart.gifContractedSubBlock.gif        Object IConvertible.ToType(Type type, IFormatProvider provider) dot.gif{
InBlock.gif            
return Convert.DefaultToType((IConvertible)this, type, provider);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

转载于:https://www.cnblogs.com/wannaCNBLOGS/archive/2005/08/04/207081.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值