mscorlib(4.0.0.0) API with additions
DateTime.cs
5 using System.Security;
6 
7 namespace System
8 {
10  [Serializable]
11  [StructLayout(LayoutKind.Auto)]
12  [__DynamicallyInvokable]
14  {
15  private const long TicksPerMillisecond = 10000L;
16 
17  private const long TicksPerSecond = 10000000L;
18 
19  private const long TicksPerMinute = 600000000L;
20 
21  private const long TicksPerHour = 36000000000L;
22 
23  private const long TicksPerDay = 864000000000L;
24 
25  private const int MillisPerSecond = 1000;
26 
27  private const int MillisPerMinute = 60000;
28 
29  private const int MillisPerHour = 3600000;
30 
31  private const int MillisPerDay = 86400000;
32 
33  private const int DaysPerYear = 365;
34 
35  private const int DaysPer4Years = 1461;
36 
37  private const int DaysPer100Years = 36524;
38 
39  private const int DaysPer400Years = 146097;
40 
41  private const int DaysTo1601 = 584388;
42 
43  private const int DaysTo1899 = 693593;
44 
45  internal const int DaysTo1970 = 719162;
46 
47  private const int DaysTo10000 = 3652059;
48 
49  internal const long MinTicks = 0L;
50 
51  internal const long MaxTicks = 3155378975999999999L;
52 
53  private const long MaxMillis = 315537897600000L;
54 
55  private const long FileTimeOffset = 504911232000000000L;
56 
57  private const long DoubleDateOffset = 599264352000000000L;
58 
59  private const long OADateMinAsTicks = 31241376000000000L;
60 
61  private const double OADateMinAsDouble = -657435.0;
62 
63  private const double OADateMaxAsDouble = 2958466.0;
64 
65  private const int DatePartYear = 0;
66 
67  private const int DatePartDayOfYear = 1;
68 
69  private const int DatePartMonth = 2;
70 
71  private const int DatePartDay = 3;
72 
73  private static readonly int[] DaysToMonth365 = new int[13]
74  {
75  0,
76  31,
77  59,
78  90,
79  120,
80  151,
81  181,
82  212,
83  243,
84  273,
85  304,
86  334,
87  365
88  };
89 
90  private static readonly int[] DaysToMonth366 = new int[13]
91  {
92  0,
93  31,
94  60,
95  91,
96  121,
97  152,
98  182,
99  213,
100  244,
101  274,
102  305,
103  335,
104  366
105  };
106 
108  [__DynamicallyInvokable]
109  public static readonly DateTime MinValue = new DateTime(0L, DateTimeKind.Unspecified);
110 
112  [__DynamicallyInvokable]
113  public static readonly DateTime MaxValue = new DateTime(3155378975999999999L, DateTimeKind.Unspecified);
114 
115  private const ulong TicksMask = 4611686018427387903uL;
116 
117  private const ulong FlagsMask = 13835058055282163712uL;
118 
119  private const ulong LocalMask = 9223372036854775808uL;
120 
121  private const long TicksCeiling = 4611686018427387904L;
122 
123  private const ulong KindUnspecified = 0uL;
124 
125  private const ulong KindUtc = 4611686018427387904uL;
126 
127  private const ulong KindLocal = 9223372036854775808uL;
128 
129  private const ulong KindLocalAmbiguousDst = 13835058055282163712uL;
130 
131  private const int KindShift = 62;
132 
133  private const string TicksField = "ticks";
134 
135  private const string DateDataField = "dateData";
136 
137  private ulong dateData;
138 
139  internal long InternalTicks => (long)(dateData & 0x3FFFFFFFFFFFFFFF);
140 
141  private ulong InternalKind => (ulong)((long)dateData & -4611686018427387904L);
142 
145  [__DynamicallyInvokable]
146  public DateTime Date
147  {
148  [__DynamicallyInvokable]
149  get
150  {
151  long internalTicks = InternalTicks;
152  return new DateTime((ulong)((internalTicks - internalTicks % 864000000000L) | (long)InternalKind));
153  }
154  }
155 
158  [__DynamicallyInvokable]
159  public int Day
160  {
161  [__DynamicallyInvokable]
162  get
163  {
164  return GetDatePart(3);
165  }
166  }
167 
170  [__DynamicallyInvokable]
171  public DayOfWeek DayOfWeek
172  {
173  [__DynamicallyInvokable]
174  get
175  {
176  return (DayOfWeek)((InternalTicks / 864000000000L + 1) % 7);
177  }
178  }
179 
182  [__DynamicallyInvokable]
183  public int DayOfYear
184  {
185  [__DynamicallyInvokable]
186  get
187  {
188  return GetDatePart(1);
189  }
190  }
191 
194  [__DynamicallyInvokable]
195  public int Hour
196  {
197  [__DynamicallyInvokable]
198  get
199  {
200  return (int)(InternalTicks / 36000000000L % 24);
201  }
202  }
203 
206  [__DynamicallyInvokable]
207  public DateTimeKind Kind
208  {
209  [__DynamicallyInvokable]
210  get
211  {
212  switch (InternalKind)
213  {
214  case 0uL:
215  return DateTimeKind.Unspecified;
216  case 4611686018427387904uL:
217  return DateTimeKind.Utc;
218  default:
219  return DateTimeKind.Local;
220  }
221  }
222  }
223 
226  [__DynamicallyInvokable]
227  public int Millisecond
228  {
229  [__DynamicallyInvokable]
230  get
231  {
232  return (int)(InternalTicks / 10000 % 1000);
233  }
234  }
235 
238  [__DynamicallyInvokable]
239  public int Minute
240  {
241  [__DynamicallyInvokable]
242  get
243  {
244  return (int)(InternalTicks / 600000000 % 60);
245  }
246  }
247 
250  [__DynamicallyInvokable]
251  public int Month
252  {
253  [__DynamicallyInvokable]
254  get
255  {
256  return GetDatePart(2);
257  }
258  }
259 
262  [__DynamicallyInvokable]
263  public static DateTime Now
264  {
265  [__DynamicallyInvokable]
266  get
267  {
268  DateTime utcNow = UtcNow;
269  bool isAmbiguousLocalDst = false;
270  long ticks = TimeZoneInfo.GetDateTimeNowUtcOffsetFromUtc(utcNow, out isAmbiguousLocalDst).Ticks;
271  long num = utcNow.Ticks + ticks;
272  if (num > 3155378975999999999L)
273  {
274  return new DateTime(3155378975999999999L, DateTimeKind.Local);
275  }
276  if (num < 0)
277  {
278  return new DateTime(0L, DateTimeKind.Local);
279  }
280  return new DateTime(num, DateTimeKind.Local, isAmbiguousLocalDst);
281  }
282  }
283 
286  [__DynamicallyInvokable]
287  public static DateTime UtcNow
288  {
289  [SecuritySafeCritical]
290  [__DynamicallyInvokable]
291  get
292  {
293  long num = 0L;
294  num = GetSystemTimeAsFileTime();
295  return new DateTime((ulong)((num + 504911232000000000L) | 0x4000000000000000));
296  }
297  }
298 
301  [__DynamicallyInvokable]
302  public int Second
303  {
304  [__DynamicallyInvokable]
305  get
306  {
307  return (int)(InternalTicks / 10000000 % 60);
308  }
309  }
310 
313  [__DynamicallyInvokable]
314  public long Ticks
315  {
316  [__DynamicallyInvokable]
317  get
318  {
319  return InternalTicks;
320  }
321  }
322 
325  [__DynamicallyInvokable]
326  public TimeSpan TimeOfDay
327  {
328  [__DynamicallyInvokable]
329  get
330  {
331  return new TimeSpan(InternalTicks % 864000000000L);
332  }
333  }
334 
337  [__DynamicallyInvokable]
338  public static DateTime Today
339  {
340  [__DynamicallyInvokable]
341  get
342  {
343  return Now.Date;
344  }
345  }
346 
349  [__DynamicallyInvokable]
350  public int Year
351  {
352  [__DynamicallyInvokable]
353  get
354  {
355  return GetDatePart(0);
356  }
357  }
358 
363  [__DynamicallyInvokable]
364  public DateTime(long ticks)
365  {
366  if (ticks < 0 || ticks > 3155378975999999999L)
367  {
368  throw new ArgumentOutOfRangeException("ticks", Environment.GetResourceString("ArgumentOutOfRange_DateTimeBadTicks"));
369  }
370  dateData = (ulong)ticks;
371  }
372 
373  private DateTime(ulong dateData)
374  {
375  this.dateData = dateData;
376  }
377 
385  [__DynamicallyInvokable]
386  public DateTime(long ticks, DateTimeKind kind)
387  {
388  if (ticks < 0 || ticks > 3155378975999999999L)
389  {
390  throw new ArgumentOutOfRangeException("ticks", Environment.GetResourceString("ArgumentOutOfRange_DateTimeBadTicks"));
391  }
392  if (kind < DateTimeKind.Unspecified || kind > DateTimeKind.Local)
393  {
394  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidDateTimeKind"), "kind");
395  }
396  dateData = (ulong)(ticks | ((long)kind << 62));
397  }
398 
399  internal DateTime(long ticks, DateTimeKind kind, bool isAmbiguousDst)
400  {
401  if (ticks < 0 || ticks > 3155378975999999999L)
402  {
403  throw new ArgumentOutOfRangeException("ticks", Environment.GetResourceString("ArgumentOutOfRange_DateTimeBadTicks"));
404  }
405  dateData = (ulong)(ticks | (isAmbiguousDst ? (-4611686018427387904L) : long.MinValue));
406  }
407 
416  [__DynamicallyInvokable]
417  public DateTime(int year, int month, int day)
418  {
419  dateData = (ulong)DateToTicks(year, month, day);
420  }
421 
433  public DateTime(int year, int month, int day, Calendar calendar)
434  {
435  this = new DateTime(year, month, day, 0, 0, 0, calendar);
436  }
437 
452  [__DynamicallyInvokable]
453  public DateTime(int year, int month, int day, int hour, int minute, int second)
454  {
455  dateData = (ulong)(DateToTicks(year, month, day) + TimeToTicks(hour, minute, second));
456  }
457 
475  [__DynamicallyInvokable]
476  public DateTime(int year, int month, int day, int hour, int minute, int second, DateTimeKind kind)
477  {
478  if (kind < DateTimeKind.Unspecified || kind > DateTimeKind.Local)
479  {
480  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidDateTimeKind"), "kind");
481  }
482  long num = DateToTicks(year, month, day) + TimeToTicks(hour, minute, second);
483  dateData = (ulong)(num | ((long)kind << 62));
484  }
485 
503  public DateTime(int year, int month, int day, int hour, int minute, int second, Calendar calendar)
504  {
505  if (calendar == null)
506  {
507  throw new ArgumentNullException("calendar");
508  }
509  dateData = (ulong)calendar.ToDateTime(year, month, day, hour, minute, second, 0).Ticks;
510  }
511 
528  [__DynamicallyInvokable]
529  public DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond)
530  {
531  if (millisecond < 0 || millisecond >= 1000)
532  {
533  throw new ArgumentOutOfRangeException("millisecond", Environment.GetResourceString("ArgumentOutOfRange_Range", 0, 999));
534  }
535  long num = DateToTicks(year, month, day) + TimeToTicks(hour, minute, second);
536  num += (long)millisecond * 10000L;
537  if (num < 0 || num > 3155378975999999999L)
538  {
539  throw new ArgumentException(Environment.GetResourceString("Arg_DateTimeRange"));
540  }
541  dateData = (ulong)num;
542  }
543 
563  [__DynamicallyInvokable]
564  public DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, DateTimeKind kind)
565  {
566  if (millisecond < 0 || millisecond >= 1000)
567  {
568  throw new ArgumentOutOfRangeException("millisecond", Environment.GetResourceString("ArgumentOutOfRange_Range", 0, 999));
569  }
570  if (kind < DateTimeKind.Unspecified || kind > DateTimeKind.Local)
571  {
572  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidDateTimeKind"), "kind");
573  }
574  long num = DateToTicks(year, month, day) + TimeToTicks(hour, minute, second);
575  num += (long)millisecond * 10000L;
576  if (num < 0 || num > 3155378975999999999L)
577  {
578  throw new ArgumentException(Environment.GetResourceString("Arg_DateTimeRange"));
579  }
580  dateData = (ulong)(num | ((long)kind << 62));
581  }
582 
602  public DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar)
603  {
604  if (calendar == null)
605  {
606  throw new ArgumentNullException("calendar");
607  }
608  if (millisecond < 0 || millisecond >= 1000)
609  {
610  throw new ArgumentOutOfRangeException("millisecond", Environment.GetResourceString("ArgumentOutOfRange_Range", 0, 999));
611  }
612  long ticks = calendar.ToDateTime(year, month, day, hour, minute, second, 0).Ticks;
613  ticks += (long)millisecond * 10000L;
614  if (ticks < 0 || ticks > 3155378975999999999L)
615  {
616  throw new ArgumentException(Environment.GetResourceString("Arg_DateTimeRange"));
617  }
618  dateData = (ulong)ticks;
619  }
620 
643  public DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar, DateTimeKind kind)
644  {
645  if (calendar == null)
646  {
647  throw new ArgumentNullException("calendar");
648  }
649  if (millisecond < 0 || millisecond >= 1000)
650  {
651  throw new ArgumentOutOfRangeException("millisecond", Environment.GetResourceString("ArgumentOutOfRange_Range", 0, 999));
652  }
653  if (kind < DateTimeKind.Unspecified || kind > DateTimeKind.Local)
654  {
655  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidDateTimeKind"), "kind");
656  }
657  long ticks = calendar.ToDateTime(year, month, day, hour, minute, second, 0).Ticks;
658  ticks += (long)millisecond * 10000L;
659  if (ticks < 0 || ticks > 3155378975999999999L)
660  {
661  throw new ArgumentException(Environment.GetResourceString("Arg_DateTimeRange"));
662  }
663  dateData = (ulong)(ticks | ((long)kind << 62));
664  }
665 
666  private DateTime(SerializationInfo info, StreamingContext context)
667  {
668  if (info == null)
669  {
670  throw new ArgumentNullException("info");
671  }
672  bool flag = false;
673  bool flag2 = false;
674  long num = 0L;
675  ulong num2 = 0uL;
676  SerializationInfoEnumerator enumerator = info.GetEnumerator();
677  while (enumerator.MoveNext())
678  {
679  string name = enumerator.Name;
680  if (!(name == "ticks"))
681  {
682  if (name == "dateData")
683  {
684  num2 = Convert.ToUInt64(enumerator.Value, CultureInfo.InvariantCulture);
685  flag2 = true;
686  }
687  }
688  else
689  {
690  num = Convert.ToInt64(enumerator.Value, CultureInfo.InvariantCulture);
691  flag = true;
692  }
693  }
694  if (flag2)
695  {
696  dateData = num2;
697  }
698  else
699  {
700  if (!flag)
701  {
702  throw new SerializationException(Environment.GetResourceString("Serialization_MissingDateTimeData"));
703  }
704  dateData = (ulong)num;
705  }
706  long internalTicks = InternalTicks;
707  if (internalTicks < 0 || internalTicks > 3155378975999999999L)
708  {
709  throw new SerializationException(Environment.GetResourceString("Serialization_DateTimeTicksOutOfRange"));
710  }
711  }
712 
717  [__DynamicallyInvokable]
718  public DateTime Add(TimeSpan value)
719  {
720  return AddTicks(value._ticks);
721  }
722 
723  private DateTime Add(double value, int scale)
724  {
725  long num = (long)(value * (double)scale + ((value >= 0.0) ? 0.5 : (-0.5)));
726  if (num <= -315537897600000L || num >= 315537897600000L)
727  {
728  throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_AddValue"));
729  }
730  return AddTicks(num * 10000);
731  }
732 
737  [__DynamicallyInvokable]
738  public DateTime AddDays(double value)
739  {
740  return Add(value, 86400000);
741  }
742 
747  [__DynamicallyInvokable]
748  public DateTime AddHours(double value)
749  {
750  return Add(value, 3600000);
751  }
752 
757  [__DynamicallyInvokable]
758  public DateTime AddMilliseconds(double value)
759  {
760  return Add(value, 1);
761  }
762 
767  [__DynamicallyInvokable]
768  public DateTime AddMinutes(double value)
769  {
770  return Add(value, 60000);
771  }
772 
778  [__DynamicallyInvokable]
779  public DateTime AddMonths(int months)
780  {
781  if (months < -120000 || months > 120000)
782  {
783  throw new ArgumentOutOfRangeException("months", Environment.GetResourceString("ArgumentOutOfRange_DateTimeBadMonths"));
784  }
785  int datePart = GetDatePart(0);
786  int datePart2 = GetDatePart(2);
787  int num = GetDatePart(3);
788  int num2 = datePart2 - 1 + months;
789  if (num2 >= 0)
790  {
791  datePart2 = num2 % 12 + 1;
792  datePart += num2 / 12;
793  }
794  else
795  {
796  datePart2 = 12 + (num2 + 1) % 12;
797  datePart += (num2 - 11) / 12;
798  }
799  if (datePart < 1 || datePart > 9999)
800  {
801  throw new ArgumentOutOfRangeException("months", Environment.GetResourceString("ArgumentOutOfRange_DateArithmetic"));
802  }
803  int num3 = DaysInMonth(datePart, datePart2);
804  if (num > num3)
805  {
806  num = num3;
807  }
808  return new DateTime((ulong)((DateToTicks(datePart, datePart2, num) + InternalTicks % 864000000000L) | (long)InternalKind));
809  }
810 
815  [__DynamicallyInvokable]
816  public DateTime AddSeconds(double value)
817  {
818  return Add(value, 1000);
819  }
820 
825  [__DynamicallyInvokable]
826  public DateTime AddTicks(long value)
827  {
828  long internalTicks = InternalTicks;
829  if (value > 3155378975999999999L - internalTicks || value < -internalTicks)
830  {
831  throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_DateArithmetic"));
832  }
833  return new DateTime((ulong)((internalTicks + value) | (long)InternalKind));
834  }
835 
841  [__DynamicallyInvokable]
842  public DateTime AddYears(int value)
843  {
844  if (value < -10000 || value > 10000)
845  {
846  throw new ArgumentOutOfRangeException("years", Environment.GetResourceString("ArgumentOutOfRange_DateTimeBadYears"));
847  }
848  return AddMonths(value * 12);
849  }
850 
858  [__DynamicallyInvokable]
859  public static int Compare(DateTime t1, DateTime t2)
860  {
861  long internalTicks = t1.InternalTicks;
862  long internalTicks2 = t2.InternalTicks;
863  if (internalTicks > internalTicks2)
864  {
865  return 1;
866  }
867  if (internalTicks < internalTicks2)
868  {
869  return -1;
870  }
871  return 0;
872  }
873 
879  public int CompareTo(object value)
880  {
881  if (value == null)
882  {
883  return 1;
884  }
885  if (!(value is DateTime))
886  {
887  throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDateTime"));
888  }
889  long internalTicks = ((DateTime)value).InternalTicks;
890  long internalTicks2 = InternalTicks;
891  if (internalTicks2 > internalTicks)
892  {
893  return 1;
894  }
895  if (internalTicks2 < internalTicks)
896  {
897  return -1;
898  }
899  return 0;
900  }
901 
905  [__DynamicallyInvokable]
906  public int CompareTo(DateTime value)
907  {
908  long internalTicks = value.InternalTicks;
909  long internalTicks2 = InternalTicks;
910  if (internalTicks2 > internalTicks)
911  {
912  return 1;
913  }
914  if (internalTicks2 < internalTicks)
915  {
916  return -1;
917  }
918  return 0;
919  }
920 
921  private static long DateToTicks(int year, int month, int day)
922  {
923  if (year >= 1 && year <= 9999 && month >= 1 && month <= 12)
924  {
925  int[] array = IsLeapYear(year) ? DaysToMonth366 : DaysToMonth365;
926  if (day >= 1 && day <= array[month] - array[month - 1])
927  {
928  int num = year - 1;
929  int num2 = num * 365 + num / 4 - num / 100 + num / 400 + array[month - 1] + day - 1;
930  return num2 * 864000000000L;
931  }
932  }
933  throw new ArgumentOutOfRangeException(null, Environment.GetResourceString("ArgumentOutOfRange_BadYearMonthDay"));
934  }
935 
936  private static long TimeToTicks(int hour, int minute, int second)
937  {
938  if (hour >= 0 && hour < 24 && minute >= 0 && minute < 60 && second >= 0 && second < 60)
939  {
940  return TimeSpan.TimeToTicks(hour, minute, second);
941  }
942  throw new ArgumentOutOfRangeException(null, Environment.GetResourceString("ArgumentOutOfRange_BadHourMinuteSecond"));
943  }
944 
952  [__DynamicallyInvokable]
953  public static int DaysInMonth(int year, int month)
954  {
955  if (month < 1 || month > 12)
956  {
957  throw new ArgumentOutOfRangeException("month", Environment.GetResourceString("ArgumentOutOfRange_Month"));
958  }
959  int[] array = IsLeapYear(year) ? DaysToMonth366 : DaysToMonth365;
960  return array[month] - array[month - 1];
961  }
962 
963  internal static long DoubleDateToTicks(double value)
964  {
965  if (!(value < 2958466.0) || !(value > -657435.0))
966  {
967  throw new ArgumentException(Environment.GetResourceString("Arg_OleAutDateInvalid"));
968  }
969  long num = (long)(value * 86400000.0 + ((value >= 0.0) ? 0.5 : (-0.5)));
970  if (num < 0)
971  {
972  num -= num % 86400000 * 2;
973  }
974  num += 59926435200000L;
975  if (num < 0 || num >= 315537897600000L)
976  {
977  throw new ArgumentException(Environment.GetResourceString("Arg_OleAutDateScale"));
978  }
979  return num * 10000;
980  }
981 
982  [DllImport("QCall", CharSet = CharSet.Unicode)]
983  [SecurityCritical]
984  [SuppressUnmanagedCodeSecurity]
985  [return: MarshalAs(UnmanagedType.Bool)]
986  internal static extern bool LegacyParseMode();
987 
988  [DllImport("QCall", CharSet = CharSet.Unicode)]
989  [SecurityCritical]
990  [SuppressUnmanagedCodeSecurity]
991  [return: MarshalAs(UnmanagedType.Bool)]
992  internal static extern bool EnableAmPmParseAdjustment();
993 
998  [__DynamicallyInvokable]
999  public override bool Equals(object value)
1000  {
1001  if (value is DateTime)
1002  {
1003  return InternalTicks == ((DateTime)value).InternalTicks;
1004  }
1005  return false;
1006  }
1007 
1013  [__DynamicallyInvokable]
1014  public bool Equals(DateTime value)
1015  {
1016  return InternalTicks == value.InternalTicks;
1017  }
1018 
1025  [__DynamicallyInvokable]
1026  public static bool Equals(DateTime t1, DateTime t2)
1027  {
1028  return t1.InternalTicks == t2.InternalTicks;
1029  }
1030 
1036  [__DynamicallyInvokable]
1037  public static DateTime FromBinary(long dateData)
1038  {
1039  if ((dateData & long.MinValue) != 0L)
1040  {
1041  long num = dateData & 0x3FFFFFFFFFFFFFFF;
1042  if (num > 4611685154427387904L)
1043  {
1044  num -= 4611686018427387904L;
1045  }
1046  bool isAmbiguousLocalDst = false;
1047  long ticks;
1048  if (num < 0)
1049  {
1050  ticks = TimeZoneInfo.GetLocalUtcOffset(MinValue, TimeZoneInfoOptions.NoThrowOnInvalidTime).Ticks;
1051  }
1052  else if (num > 3155378975999999999L)
1053  {
1054  ticks = TimeZoneInfo.GetLocalUtcOffset(MaxValue, TimeZoneInfoOptions.NoThrowOnInvalidTime).Ticks;
1055  }
1056  else
1057  {
1058  DateTime time = new DateTime(num, DateTimeKind.Utc);
1059  bool isDaylightSavings = false;
1060  ticks = TimeZoneInfo.GetUtcOffsetFromUtc(time, TimeZoneInfo.Local, out isDaylightSavings, out isAmbiguousLocalDst).Ticks;
1061  }
1062  num += ticks;
1063  if (num < 0)
1064  {
1065  num += 864000000000L;
1066  }
1067  if (num < 0 || num > 3155378975999999999L)
1068  {
1069  throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeBadBinaryData"), "dateData");
1070  }
1071  return new DateTime(num, DateTimeKind.Local, isAmbiguousLocalDst);
1072  }
1073  return FromBinaryRaw(dateData);
1074  }
1075 
1076  internal static DateTime FromBinaryRaw(long dateData)
1077  {
1078  long num = dateData & 0x3FFFFFFFFFFFFFFF;
1079  if (num < 0 || num > 3155378975999999999L)
1080  {
1081  throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeBadBinaryData"), "dateData");
1082  }
1083  return new DateTime((ulong)dateData);
1084  }
1085 
1091  [__DynamicallyInvokable]
1092  public static DateTime FromFileTime(long fileTime)
1093  {
1094  return FromFileTimeUtc(fileTime).ToLocalTime();
1095  }
1096 
1102  [__DynamicallyInvokable]
1103  public static DateTime FromFileTimeUtc(long fileTime)
1104  {
1105  if (fileTime < 0 || fileTime > 2650467743999999999L)
1106  {
1107  throw new ArgumentOutOfRangeException("fileTime", Environment.GetResourceString("ArgumentOutOfRange_FileTimeInvalid"));
1108  }
1109  long ticks = fileTime + 504911232000000000L;
1110  return new DateTime(ticks, DateTimeKind.Utc);
1111  }
1112 
1117  [__DynamicallyInvokable]
1118  public static DateTime FromOADate(double d)
1119  {
1120  return new DateTime(DoubleDateToTicks(d), DateTimeKind.Unspecified);
1121  }
1122 
1128  [SecurityCritical]
1130  {
1131  if (info == null)
1132  {
1133  throw new ArgumentNullException("info");
1134  }
1135  info.AddValue("ticks", InternalTicks);
1136  info.AddValue("dateData", dateData);
1137  }
1138 
1142  [__DynamicallyInvokable]
1143  public bool IsDaylightSavingTime()
1144  {
1145  if (Kind == DateTimeKind.Utc)
1146  {
1147  return false;
1148  }
1149  return TimeZoneInfo.Local.IsDaylightSavingTime(this, TimeZoneInfoOptions.NoThrowOnInvalidTime);
1150  }
1151 
1156  [__DynamicallyInvokable]
1157  public static DateTime SpecifyKind(DateTime value, DateTimeKind kind)
1158  {
1159  return new DateTime(value.InternalTicks, kind);
1160  }
1161 
1164  [__DynamicallyInvokable]
1165  public long ToBinary()
1166  {
1167  if (Kind == DateTimeKind.Local)
1168  {
1169  TimeSpan localUtcOffset = TimeZoneInfo.GetLocalUtcOffset(this, TimeZoneInfoOptions.NoThrowOnInvalidTime);
1170  long ticks = Ticks;
1171  long num = ticks - localUtcOffset.Ticks;
1172  if (num < 0)
1173  {
1174  num = 4611686018427387904L + num;
1175  }
1176  return num | long.MinValue;
1177  }
1178  return (long)dateData;
1179  }
1180 
1181  internal long ToBinaryRaw()
1182  {
1183  return (long)dateData;
1184  }
1185 
1186  private int GetDatePart(int part)
1187  {
1188  long internalTicks = InternalTicks;
1189  int num = (int)(internalTicks / 864000000000L);
1190  int num2 = num / 146097;
1191  num -= num2 * 146097;
1192  int num3 = num / 36524;
1193  if (num3 == 4)
1194  {
1195  num3 = 3;
1196  }
1197  num -= num3 * 36524;
1198  int num4 = num / 1461;
1199  num -= num4 * 1461;
1200  int num5 = num / 365;
1201  if (num5 == 4)
1202  {
1203  num5 = 3;
1204  }
1205  if (part == 0)
1206  {
1207  return num2 * 400 + num3 * 100 + num4 * 4 + num5 + 1;
1208  }
1209  num -= num5 * 365;
1210  if (part == 1)
1211  {
1212  return num + 1;
1213  }
1214  int[] array = (num5 == 3 && (num4 != 24 || num3 == 3)) ? DaysToMonth366 : DaysToMonth365;
1215  int i;
1216  for (i = num >> 6; num >= array[i]; i++)
1217  {
1218  }
1219  if (part == 2)
1220  {
1221  return i;
1222  }
1223  return num - array[i - 1] + 1;
1224  }
1225 
1228  [__DynamicallyInvokable]
1229  public override int GetHashCode()
1230  {
1231  long internalTicks = InternalTicks;
1232  return (int)internalTicks ^ (int)(internalTicks >> 32);
1233  }
1234 
1235  internal bool IsAmbiguousDaylightSavingTime()
1236  {
1237  return InternalKind == 13835058055282163712uL;
1238  }
1239 
1240  [MethodImpl(MethodImplOptions.InternalCall)]
1241  [SecurityCritical]
1242  internal static extern long GetSystemTimeAsFileTime();
1243 
1250  [__DynamicallyInvokable]
1251  public static bool IsLeapYear(int year)
1252  {
1253  if (year < 1 || year > 9999)
1254  {
1255  throw new ArgumentOutOfRangeException("year", Environment.GetResourceString("ArgumentOutOfRange_Year"));
1256  }
1257  if (year % 4 == 0)
1258  {
1259  if (year % 100 == 0)
1260  {
1261  return year % 400 == 0;
1262  }
1263  return true;
1264  }
1265  return false;
1266  }
1267 
1275  [__DynamicallyInvokable]
1276  public static DateTime Parse(string s)
1277  {
1278  return DateTimeParse.Parse(s, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None);
1279  }
1280 
1289  [__DynamicallyInvokable]
1290  public static DateTime Parse(string s, IFormatProvider provider)
1291  {
1292  return DateTimeParse.Parse(s, DateTimeFormatInfo.GetInstance(provider), DateTimeStyles.None);
1293  }
1294 
1306  [__DynamicallyInvokable]
1307  public static DateTime Parse(string s, IFormatProvider provider, DateTimeStyles styles)
1308  {
1309  DateTimeFormatInfo.ValidateStyles(styles, "styles");
1310  return DateTimeParse.Parse(s, DateTimeFormatInfo.GetInstance(provider), styles);
1311  }
1312 
1324  [__DynamicallyInvokable]
1325  public static DateTime ParseExact(string s, string format, IFormatProvider provider)
1326  {
1327  return DateTimeParse.ParseExact(s, format, DateTimeFormatInfo.GetInstance(provider), DateTimeStyles.None);
1328  }
1329 
1344  [__DynamicallyInvokable]
1345  public static DateTime ParseExact(string s, string format, IFormatProvider provider, DateTimeStyles style)
1346  {
1347  DateTimeFormatInfo.ValidateStyles(style, "style");
1348  return DateTimeParse.ParseExact(s, format, DateTimeFormatInfo.GetInstance(provider), style);
1349  }
1350 
1365  [__DynamicallyInvokable]
1366  public static DateTime ParseExact(string s, string[] formats, IFormatProvider provider, DateTimeStyles style)
1367  {
1368  DateTimeFormatInfo.ValidateStyles(style, "style");
1369  return DateTimeParse.ParseExactMultiple(s, formats, DateTimeFormatInfo.GetInstance(provider), style);
1370  }
1371 
1376  [__DynamicallyInvokable]
1378  {
1379  return new TimeSpan(InternalTicks - value.InternalTicks);
1380  }
1381 
1386  [__DynamicallyInvokable]
1388  {
1389  long internalTicks = InternalTicks;
1390  long ticks = value._ticks;
1391  if (internalTicks - 0 < ticks || internalTicks - 3155378975999999999L > ticks)
1392  {
1393  throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_DateArithmetic"));
1394  }
1395  return new DateTime((ulong)((internalTicks - ticks) | (long)InternalKind));
1396  }
1397 
1398  private static double TicksToOADate(long value)
1399  {
1400  if (value == 0L)
1401  {
1402  return 0.0;
1403  }
1404  if (value < 864000000000L)
1405  {
1406  value += 599264352000000000L;
1407  }
1408  if (value < 31241376000000000L)
1409  {
1410  throw new OverflowException(Environment.GetResourceString("Arg_OleAutDateInvalid"));
1411  }
1412  long num = (value - 599264352000000000L) / 10000;
1413  if (num < 0)
1414  {
1415  long num2 = num % 86400000;
1416  if (num2 != 0L)
1417  {
1418  num -= (86400000 + num2) * 2;
1419  }
1420  }
1421  return (double)num / 86400000.0;
1422  }
1423 
1427  [__DynamicallyInvokable]
1428  public double ToOADate()
1429  {
1430  return TicksToOADate(InternalTicks);
1431  }
1432 
1436  [__DynamicallyInvokable]
1437  public long ToFileTime()
1438  {
1439  return ToUniversalTime().ToFileTimeUtc();
1440  }
1441 
1445  [__DynamicallyInvokable]
1446  public long ToFileTimeUtc()
1447  {
1448  long num = (((long)InternalKind & long.MinValue) != 0L) ? ToUniversalTime().InternalTicks : InternalTicks;
1449  num -= 504911232000000000L;
1450  if (num < 0)
1451  {
1452  throw new ArgumentOutOfRangeException(null, Environment.GetResourceString("ArgumentOutOfRange_FileTimeInvalid"));
1453  }
1454  return num;
1455  }
1456 
1459  [__DynamicallyInvokable]
1461  {
1462  return ToLocalTime(throwOnOverflow: false);
1463  }
1464 
1465  internal DateTime ToLocalTime(bool throwOnOverflow)
1466  {
1467  if (Kind == DateTimeKind.Local)
1468  {
1469  return this;
1470  }
1471  bool isDaylightSavings = false;
1472  bool isAmbiguousLocalDst = false;
1473  long ticks = TimeZoneInfo.GetUtcOffsetFromUtc(this, TimeZoneInfo.Local, out isDaylightSavings, out isAmbiguousLocalDst).Ticks;
1474  long num = Ticks + ticks;
1475  if (num > 3155378975999999999L)
1476  {
1477  if (throwOnOverflow)
1478  {
1479  throw new ArgumentException(Environment.GetResourceString("Arg_ArgumentOutOfRangeException"));
1480  }
1481  return new DateTime(3155378975999999999L, DateTimeKind.Local);
1482  }
1483  if (num < 0)
1484  {
1485  if (throwOnOverflow)
1486  {
1487  throw new ArgumentException(Environment.GetResourceString("Arg_ArgumentOutOfRangeException"));
1488  }
1489  return new DateTime(0L, DateTimeKind.Local);
1490  }
1491  return new DateTime(num, DateTimeKind.Local, isAmbiguousLocalDst);
1492  }
1493 
1496  public string ToLongDateString()
1497  {
1498  return DateTimeFormat.Format(this, "D", DateTimeFormatInfo.CurrentInfo);
1499  }
1500 
1503  public string ToLongTimeString()
1504  {
1505  return DateTimeFormat.Format(this, "T", DateTimeFormatInfo.CurrentInfo);
1506  }
1507 
1510  public string ToShortDateString()
1511  {
1512  return DateTimeFormat.Format(this, "d", DateTimeFormatInfo.CurrentInfo);
1513  }
1514 
1517  public string ToShortTimeString()
1518  {
1519  return DateTimeFormat.Format(this, "t", DateTimeFormatInfo.CurrentInfo);
1520  }
1521 
1525  [__DynamicallyInvokable]
1526  public override string ToString()
1527  {
1528  return DateTimeFormat.Format(this, null, DateTimeFormatInfo.CurrentInfo);
1529  }
1530 
1537  [__DynamicallyInvokable]
1538  public string ToString(string format)
1539  {
1540  return DateTimeFormat.Format(this, format, DateTimeFormatInfo.CurrentInfo);
1541  }
1542 
1547  [__DynamicallyInvokable]
1548  public string ToString(IFormatProvider provider)
1549  {
1550  return DateTimeFormat.Format(this, null, DateTimeFormatInfo.GetInstance(provider));
1551  }
1552 
1560  [__DynamicallyInvokable]
1561  public string ToString(string format, IFormatProvider provider)
1562  {
1563  return DateTimeFormat.Format(this, format, DateTimeFormatInfo.GetInstance(provider));
1564  }
1565 
1568  [__DynamicallyInvokable]
1570  {
1571  return TimeZoneInfo.ConvertTimeToUtc(this, TimeZoneInfoOptions.NoThrowOnInvalidTime);
1572  }
1573 
1579  [__DynamicallyInvokable]
1580  public static bool TryParse(string s, out DateTime result)
1581  {
1582  return DateTimeParse.TryParse(s, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None, out result);
1583  }
1584 
1597  [__DynamicallyInvokable]
1598  public static bool TryParse(string s, IFormatProvider provider, DateTimeStyles styles, out DateTime result)
1599  {
1600  DateTimeFormatInfo.ValidateStyles(styles, "styles");
1601  return DateTimeParse.TryParse(s, DateTimeFormatInfo.GetInstance(provider), styles, out result);
1602  }
1603 
1615  [__DynamicallyInvokable]
1616  public static bool TryParseExact(string s, string format, IFormatProvider provider, DateTimeStyles style, out DateTime result)
1617  {
1618  DateTimeFormatInfo.ValidateStyles(style, "style");
1619  return DateTimeParse.TryParseExact(s, format, DateTimeFormatInfo.GetInstance(provider), style, out result);
1620  }
1621 
1633  [__DynamicallyInvokable]
1634  public static bool TryParseExact(string s, string[] formats, IFormatProvider provider, DateTimeStyles style, out DateTime result)
1635  {
1636  DateTimeFormatInfo.ValidateStyles(style, "style");
1637  return DateTimeParse.TryParseExactMultiple(s, formats, DateTimeFormatInfo.GetInstance(provider), style, out result);
1638  }
1639 
1645  [__DynamicallyInvokable]
1646  public static DateTime operator +(DateTime d, TimeSpan t)
1647  {
1648  long internalTicks = d.InternalTicks;
1649  long ticks = t._ticks;
1650  if (ticks > 3155378975999999999L - internalTicks || ticks < -internalTicks)
1651  {
1652  throw new ArgumentOutOfRangeException("t", Environment.GetResourceString("ArgumentOutOfRange_DateArithmetic"));
1653  }
1654  return new DateTime((ulong)((internalTicks + ticks) | (long)d.InternalKind));
1655  }
1656 
1662  [__DynamicallyInvokable]
1663  public static DateTime operator -(DateTime d, TimeSpan t)
1664  {
1665  long internalTicks = d.InternalTicks;
1666  long ticks = t._ticks;
1667  if (internalTicks - 0 < ticks || internalTicks - 3155378975999999999L > ticks)
1668  {
1669  throw new ArgumentOutOfRangeException("t", Environment.GetResourceString("ArgumentOutOfRange_DateArithmetic"));
1670  }
1671  return new DateTime((ulong)((internalTicks - ticks) | (long)d.InternalKind));
1672  }
1673 
1678  [__DynamicallyInvokable]
1679  public static TimeSpan operator -(DateTime d1, DateTime d2)
1680  {
1681  return new TimeSpan(d1.InternalTicks - d2.InternalTicks);
1682  }
1683 
1689  [__DynamicallyInvokable]
1690  public static bool operator ==(DateTime d1, DateTime d2)
1691  {
1692  return d1.InternalTicks == d2.InternalTicks;
1693  }
1694 
1700  [__DynamicallyInvokable]
1701  public static bool operator !=(DateTime d1, DateTime d2)
1702  {
1703  return d1.InternalTicks != d2.InternalTicks;
1704  }
1705 
1711  [__DynamicallyInvokable]
1712  public static bool operator <(DateTime t1, DateTime t2)
1713  {
1714  return t1.InternalTicks < t2.InternalTicks;
1715  }
1716 
1722  [__DynamicallyInvokable]
1723  public static bool operator <=(DateTime t1, DateTime t2)
1724  {
1725  return t1.InternalTicks <= t2.InternalTicks;
1726  }
1727 
1733  [__DynamicallyInvokable]
1734  public static bool operator >(DateTime t1, DateTime t2)
1735  {
1736  return t1.InternalTicks > t2.InternalTicks;
1737  }
1738 
1744  [__DynamicallyInvokable]
1745  public static bool operator >=(DateTime t1, DateTime t2)
1746  {
1747  return t1.InternalTicks >= t2.InternalTicks;
1748  }
1749 
1752  [__DynamicallyInvokable]
1753  public string[] GetDateTimeFormats()
1754  {
1756  }
1757 
1761  [__DynamicallyInvokable]
1762  public string[] GetDateTimeFormats(IFormatProvider provider)
1763  {
1764  return DateTimeFormat.GetAllDateTimes(this, DateTimeFormatInfo.GetInstance(provider));
1765  }
1766 
1772  [__DynamicallyInvokable]
1773  public string[] GetDateTimeFormats(char format)
1774  {
1776  }
1777 
1784  [__DynamicallyInvokable]
1785  public string[] GetDateTimeFormats(char format, IFormatProvider provider)
1786  {
1787  return DateTimeFormat.GetAllDateTimes(this, format, DateTimeFormatInfo.GetInstance(provider));
1788  }
1789 
1793  {
1794  return TypeCode.DateTime;
1795  }
1796 
1801  [__DynamicallyInvokable]
1803  {
1804  throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", "DateTime", "Boolean"));
1805  }
1806 
1811  [__DynamicallyInvokable]
1813  {
1814  throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", "DateTime", "Char"));
1815  }
1816 
1821  [__DynamicallyInvokable]
1823  {
1824  throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", "DateTime", "SByte"));
1825  }
1826 
1831  [__DynamicallyInvokable]
1833  {
1834  throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", "DateTime", "Byte"));
1835  }
1836 
1841  [__DynamicallyInvokable]
1843  {
1844  throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", "DateTime", "Int16"));
1845  }
1846 
1851  [__DynamicallyInvokable]
1853  {
1854  throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", "DateTime", "UInt16"));
1855  }
1856 
1861  [__DynamicallyInvokable]
1863  {
1864  throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", "DateTime", "Int32"));
1865  }
1866 
1871  [__DynamicallyInvokable]
1873  {
1874  throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", "DateTime", "UInt32"));
1875  }
1876 
1881  [__DynamicallyInvokable]
1883  {
1884  throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", "DateTime", "Int64"));
1885  }
1886 
1891  [__DynamicallyInvokable]
1893  {
1894  throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", "DateTime", "UInt64"));
1895  }
1896 
1901  [__DynamicallyInvokable]
1903  {
1904  throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", "DateTime", "Single"));
1905  }
1906 
1911  [__DynamicallyInvokable]
1913  {
1914  throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", "DateTime", "Double"));
1915  }
1916 
1921  [__DynamicallyInvokable]
1923  {
1924  throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", "DateTime", "Decimal"));
1925  }
1926 
1930  [__DynamicallyInvokable]
1932  {
1933  return this;
1934  }
1935 
1943  [__DynamicallyInvokable]
1944  object IConvertible.ToType(Type type, IFormatProvider provider)
1945  {
1946  return Convert.DefaultToType(this, type, provider);
1947  }
1948 
1949  internal static bool TryCreate(int year, int month, int day, int hour, int minute, int second, int millisecond, out DateTime result)
1950  {
1951  result = MinValue;
1952  if (year < 1 || year > 9999 || month < 1 || month > 12)
1953  {
1954  return false;
1955  }
1956  int[] array = IsLeapYear(year) ? DaysToMonth366 : DaysToMonth365;
1957  if (day < 1 || day > array[month] - array[month - 1])
1958  {
1959  return false;
1960  }
1961  if (hour < 0 || hour >= 24 || minute < 0 || minute >= 60 || second < 0 || second >= 60)
1962  {
1963  return false;
1964  }
1965  if (millisecond < 0 || millisecond >= 1000)
1966  {
1967  return false;
1968  }
1969  long num = DateToTicks(year, month, day) + TimeToTicks(hour, minute, second);
1970  num += (long)millisecond * 10000L;
1971  if (num < 0 || num > 3155378975999999999L)
1972  {
1973  return false;
1974  }
1975  result = new DateTime(num, DateTimeKind.Unspecified);
1976  return true;
1977  }
1978  }
1979 }
float ToSingle(IFormatProvider provider)
Converts the value of this instance to an equivalent single-precision floating-point number using the...
Converts a base data type to another base data type.
Definition: Convert.cs:10
static bool operator >=(DateTime t1, DateTime t2)
Determines whether one specified T:System.DateTime represents a date and time that is the same as or ...
Definition: DateTime.cs:1745
DateTime(long ticks, DateTimeKind kind)
Initializes a new instance of the T:System.DateTime structure to a specified number of ticks and to C...
Definition: DateTime.cs:386
Represents any time zone in the world.
Definition: TimeZoneInfo.cs:20
static int DaysInMonth(int year, int month)
Returns the number of days in the specified month and year.
Definition: DateTime.cs:953
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
Definition: CultureInfo.cs:263
string ToString(IFormatProvider provider)
Converts the value of the current T:System.DateTime object to its equivalent string representation us...
Definition: DateTime.cs:1548
DateTime AddYears(int value)
Returns a new T:System.DateTime that adds the specified number of years to the value of this instance...
Definition: DateTime.cs:842
static bool operator !=(DateTime d1, DateTime d2)
Determines whether two specified instances of T:System.DateTime are not equal.
Definition: DateTime.cs:1701
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Represents time in divisions, such as weeks, months, and years.
Definition: Calendar.cs:11
static DateTime ParseExact(string s, string format, IFormatProvider provider)
Converts the specified string representation of a date and time to its T:System.DateTime equivalent u...
Definition: DateTime.cs:1325
DateTime(int year, int month, int day)
Initializes a new instance of the T:System.DateTime structure to the specified year,...
Definition: DateTime.cs:417
static DateTime FromFileTime(long fileTime)
Converts the specified Windows file time to an equivalent local time.
Definition: DateTime.cs:1092
string ToShortDateString()
Converts the value of the current T:System.DateTime object to its equivalent short date string repres...
Definition: DateTime.cs:1510
bool IsDaylightSavingTime()
Indicates whether this instance of T:System.DateTime is within the daylight saving time range for the...
Definition: DateTime.cs:1143
double ToDouble(IFormatProvider provider)
Converts the value of this instance to an equivalent double-precision floating-point number using the...
static DateTime Parse(string s, IFormatProvider provider)
Converts the string representation of a date and time to its T:System.DateTime equivalent by using cu...
Definition: DateTime.cs:1290
bool IsDaylightSavingTime(DateTimeOffset dateTimeOffset)
Indicates whether a specified date and time falls in the range of daylight saving time for the time z...
long ToFileTimeUtc()
Converts the value of the current T:System.DateTime object to a Windows file time.
Definition: DateTime.cs:1446
static readonly DateTime MinValue
Represents the smallest possible value of T:System.DateTime. This field is read-only.
Definition: DateTime.cs:109
object Value
Gets the value of the item currently being examined.
bool ToBoolean(IFormatProvider provider)
Converts the value of this instance to an equivalent Boolean value using the specified culture-specif...
TypeCode
Specifies the type of an object.
Definition: TypeCode.cs:9
LayoutKind
Controls the layout of an object when exported to unmanaged code.
Definition: LayoutKind.cs:7
static TimeSpan operator -(DateTime d1, DateTime d2)
Subtracts a specified date and time from another specified date and time and returns a time interval.
Definition: DateTime.cs:1679
Definition: __Canon.cs:3
The exception that is thrown when the value of an argument is outside the allowable range of values a...
DateTime(int year, int month, int day, int hour, int minute, int second)
Initializes a new instance of the T:System.DateTime structure to the specified year,...
Definition: DateTime.cs:453
bool Equals(DateTime value)
Returns a value indicating whether the value of this instance is equal to the value of the specified ...
Definition: DateTime.cs:1014
The exception that is thrown for invalid casting or explicit conversion.
DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar)
Initializes a new instance of the T:System.DateTime structure to the specified year,...
Definition: DateTime.cs:602
char ToChar(IFormatProvider provider)
Converts the value of this instance to an equivalent Unicode character using the specified culture-sp...
string ToString(string format, IFormatProvider provider)
Converts the value of the current T:System.DateTime object to its equivalent string representation us...
Definition: DateTime.cs:1561
DateTime Subtract(TimeSpan value)
Subtracts the specified duration from this instance.
Definition: DateTime.cs:1387
Provides a mechanism for retrieving an object to control formatting.
TimeSpan TimeOfDay
Gets the time of day for this instance.
Definition: DateTime.cs:327
Represents an instant in time, typically expressed as a date and time of day. To browse the ....
Definition: DateTime.cs:13
static bool IsLeapYear(int year)
Returns an indication whether the specified year is a leap year.
Definition: DateTime.cs:1251
DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar, DateTimeKind kind)
Initializes a new instance of the T:System.DateTime structure to the specified year,...
Definition: DateTime.cs:643
string [] GetDateTimeFormats(IFormatProvider provider)
Converts the value of this instance to all the string representations supported by the standard date ...
Definition: DateTime.cs:1762
TypeCode GetTypeCode()
Returns the T:System.TypeCode for value type T:System.DateTime.
Definition: DateTime.cs:1792
DateTime ToDateTime(IFormatProvider provider)
Converts the value of this instance to an equivalent T:System.DateTime using the specified culture-sp...
Provides culture-specific information about the format of date and time values.
Describes the source and destination of a given serialized stream, and provides an additional caller-...
sbyte ToSByte(IFormatProvider provider)
Converts the value of this instance to an equivalent 8-bit signed integer using the specified culture...
Defines a generalized type-specific comparison method that a value type or class implements to order ...
Definition: IComparable.cs:8
int CompareTo(object value)
Compares the value of this instance to a specified object that contains a specified T:System....
Definition: DateTime.cs:879
static DateTime FromFileTimeUtc(long fileTime)
Converts the specified Windows file time to an equivalent UTC time.
Definition: DateTime.cs:1103
int Second
Gets the seconds component of the date represented by this instance.
Definition: DateTime.cs:303
DateTime ToLocalTime()
Converts the value of the current T:System.DateTime object to local time.
Definition: DateTime.cs:1460
DateTime(int year, int month, int day, Calendar calendar)
Initializes a new instance of the T:System.DateTime structure to the specified year,...
Definition: DateTime.cs:433
string ToShortTimeString()
Converts the value of the current T:System.DateTime object to its equivalent short time string repres...
Definition: DateTime.cs:1517
int Hour
Gets the hour component of the date represented by this instance.
Definition: DateTime.cs:196
long Ticks
Gets the number of ticks that represent the value of the current T:System.TimeSpan structure.
Definition: TimeSpan.cs:84
int Year
Gets the year component of the date represented by this instance.
Definition: DateTime.cs:351
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
override int GetHashCode()
Returns the hash code for this instance.
Definition: DateTime.cs:1229
string ToLongTimeString()
Converts the value of the current T:System.DateTime object to its equivalent long time string represe...
Definition: DateTime.cs:1503
string ToLongDateString()
Converts the value of the current T:System.DateTime object to its equivalent long date string represe...
Definition: DateTime.cs:1496
static DateTime Parse(string s)
Converts the string representation of a date and time to its T:System.DateTime equivalent.
Definition: DateTime.cs:1276
decimal ToDecimal(IFormatProvider provider)
Converts the value of this instance to an equivalent T:System.Decimal number using the specified cult...
string ToString(string format)
Converts the value of the current T:System.DateTime object to its equivalent string representation us...
Definition: DateTime.cs:1538
static DateTime FromBinary(long dateData)
Deserializes a 64-bit binary value and recreates an original serialized T:System.DateTime object.
Definition: DateTime.cs:1037
DateTimeKind Kind
Gets a value that indicates whether the time represented by this instance is based on local time,...
Definition: DateTime.cs:208
override string ToString()
Converts the value of the current T:System.DateTime object to its equivalent string representation us...
Definition: DateTime.cs:1526
A cast or conversion operation, such as (SampleType)obj in C::or CType(obj, SampleType) in Visual Bas...
int ToInt32(IFormatProvider provider)
Converts the value of this instance to an equivalent 32-bit signed integer using the specified cultur...
UnmanagedType
Identifies how to marshal parameters or fields to unmanaged code.
Definition: UnmanagedType.cs:7
static bool TryParse(string s, out DateTime result)
Converts the specified string representation of a date and time to its T:System.DateTime equivalent a...
Definition: DateTime.cs:1580
static bool operator<(DateTime t1, DateTime t2)
Determines whether one specified T:System.DateTime is earlier than another specified T:System....
Definition: DateTime.cs:1712
DateTime AddDays(double value)
Returns a new T:System.DateTime that adds the specified number of days to the value of this instance.
Definition: DateTime.cs:738
static DateTime ParseExact(string s, string format, IFormatProvider provider, DateTimeStyles style)
Converts the specified string representation of a date and time to its T:System.DateTime equivalent u...
Definition: DateTime.cs:1345
DateTime AddMonths(int months)
Returns a new T:System.DateTime that adds the specified number of months to the value of this instanc...
Definition: DateTime.cs:779
static readonly DateTime MaxValue
Represents the largest possible value of T:System.DateTime. This field is read-only.
Definition: DateTime.cs:113
static DateTime ParseExact(string s, string[] formats, IFormatProvider provider, DateTimeStyles style)
Converts the specified string representation of a date and time to its T:System.DateTime equivalent u...
Definition: DateTime.cs:1366
int Minute
Gets the minute component of the date represented by this instance.
Definition: DateTime.cs:240
DateTime Date
Gets the date component of this instance.
Definition: DateTime.cs:147
DateTime Add(TimeSpan value)
Returns a new T:System.DateTime that adds the value of the specified T:System.TimeSpan to the value o...
Definition: DateTime.cs:718
TimeSpan Subtract(DateTime value)
Subtracts the specified date and time from this instance.
Definition: DateTime.cs:1377
long ToFileTime()
Converts the value of the current T:System.DateTime object to a Windows file time.
Definition: DateTime.cs:1437
override bool Equals(object value)
Returns a value indicating whether this instance is equal to a specified object.
Definition: DateTime.cs:999
object ToType(Type conversionType, IFormatProvider provider)
Converts the value of this instance to an T:System.Object of the specified T:System....
static DateTimeFormatInfo CurrentInfo
Gets a read-only T:System.Globalization.DateTimeFormatInfo object that formats values based on the cu...
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
The exception thrown when an error occurs during serialization or deserialization.
static DateTime SpecifyKind(DateTime value, DateTimeKind kind)
Creates a new T:System.DateTime object that has the same number of ticks as the specified T:System....
Definition: DateTime.cs:1157
static DateTime UtcNow
Gets a T:System.DateTime object that is set to the current date and time on this computer,...
Definition: DateTime.cs:288
ushort ToUInt16(IFormatProvider provider)
Converts the value of this instance to an equivalent 16-bit unsigned integer using the specified cult...
MethodImplOptions
Defines the details of how a method is implemented.
string [] GetDateTimeFormats(char format)
Converts the value of this instance to all the string representations supported by the specified stan...
Definition: DateTime.cs:1773
CharSet
Dictates which character set marshaled strings should use.
Definition: CharSet.cs:7
int Day
Gets the day of the month represented by this instance.
Definition: DateTime.cs:160
long ToBinary()
Serializes the current T:System.DateTime object to a 64-bit binary value that subsequently can be use...
Definition: DateTime.cs:1165
DateTime(long ticks)
Initializes a new instance of the T:System.DateTime structure to a specified number of ticks.
Definition: DateTime.cs:364
DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, DateTimeKind kind)
Initializes a new instance of the T:System.DateTime structure to the specified year,...
Definition: DateTime.cs:564
static bool TryParseExact(string s, string[] formats, IFormatProvider provider, DateTimeStyles style, out DateTime result)
Converts the specified string representation of a date and time to its T:System.DateTime equivalent u...
Definition: DateTime.cs:1634
int CompareTo(DateTime value)
Compares the value of this instance to a specified T:System.DateTime value and returns an integer tha...
Definition: DateTime.cs:906
double ToOADate()
Converts the value of this instance to the equivalent OLE Automation date.
Definition: DateTime.cs:1428
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
short ToInt16(IFormatProvider provider)
Converts the value of this instance to an equivalent 16-bit signed integer using the specified cultur...
static bool TryParseExact(string s, string format, IFormatProvider provider, DateTimeStyles style, out DateTime result)
Converts the specified string representation of a date and time to its T:System.DateTime equivalent u...
Definition: DateTime.cs:1616
static DateTime Today
Gets the current date.
Definition: DateTime.cs:339
static CultureInfo CurrentCulture
Gets or sets the T:System.Globalization.CultureInfo object that represents the culture used by the cu...
Definition: CultureInfo.cs:120
long ToInt64(IFormatProvider provider)
Converts the value of this instance to an equivalent 64-bit signed integer using the specified cultur...
The exception that is thrown when one of the arguments provided to a method is not valid.
static bool operator==(DateTime d1, DateTime d2)
Determines whether two specified instances of T:System.DateTime are equal.
Definition: DateTime.cs:1690
Allows an object to control its own serialization and deserialization.
Definition: ISerializable.cs:8
DateTime AddMilliseconds(double value)
Returns a new T:System.DateTime that adds the specified number of milliseconds to the value of this i...
Definition: DateTime.cs:758
string [] GetDateTimeFormats(char format, IFormatProvider provider)
Converts the value of this instance to all the string representations supported by the specified stan...
Definition: DateTime.cs:1785
int Month
Gets the month component of the date represented by this instance.
Definition: DateTime.cs:252
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition: IEquatable.cs:6
DateTimeKind
Specifies whether a T:System.DateTime object represents a local time, a Coordinated Universal Time (U...
Definition: DateTimeKind.cs:9
DateTime AddHours(double value)
Returns a new T:System.DateTime that adds the specified number of hours to the value of this instance...
Definition: DateTime.cs:748
static DateTime FromOADate(double d)
Returns a T:System.DateTime equivalent to the specified OLE Automation Date.
Definition: DateTime.cs:1118
DateTime(int year, int month, int day, int hour, int minute, int second, DateTimeKind kind)
Initializes a new instance of the T:System.DateTime structure to the specified year,...
Definition: DateTime.cs:476
Represents a time interval.To browse the .NET Framework source code for this type,...
Definition: TimeSpan.cs:12
int DayOfYear
Gets the day of the year represented by this instance.
Definition: DateTime.cs:184
Specifies that the class can be serialized.
static DateTime Parse(string s, IFormatProvider provider, DateTimeStyles styles)
Converts the string representation of a date and time to its T:System.DateTime equivalent by using cu...
Definition: DateTime.cs:1307
string Name
Gets the name for the item currently being examined.
static DateTime Now
Gets a T:System.DateTime object that is set to the current date and time on this computer,...
Definition: DateTime.cs:264
DateTime(int year, int month, int day, int hour, int minute, int second, Calendar calendar)
Initializes a new instance of the T:System.DateTime structure to the specified year,...
Definition: DateTime.cs:503
static DateTime ConvertTimeToUtc(DateTime dateTime)
Converts the specified date and time to Coordinated Universal Time (UTC).
static int Compare(DateTime t1, DateTime t2)
Compares two instances of T:System.DateTime and returns an integer that indicates whether the first i...
Definition: DateTime.cs:859
static DateTime operator+(DateTime d, TimeSpan t)
Adds a specified time interval to a specified date and time, yielding a new date and time.
Definition: DateTime.cs:1646
static bool Equals(DateTime t1, DateTime t2)
Returns a value indicating whether two T:System.DateTime instances have the same date and time value.
Definition: DateTime.cs:1026
ulong ToUInt64(IFormatProvider provider)
Converts the value of this instance to an equivalent 64-bit unsigned integer using the specified cult...
DateTime AddMinutes(double value)
Returns a new T:System.DateTime that adds the specified number of minutes to the value of this instan...
Definition: DateTime.cs:768
byte ToByte(IFormatProvider provider)
Converts the value of this instance to an equivalent 8-bit unsigned integer using the specified cultu...
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
DateTime ToUniversalTime()
Converts the value of the current T:System.DateTime object to Coordinated Universal Time (UTC).
Definition: DateTime.cs:1569
Defines methods that convert the value of the implementing reference or value type to a common langua...
Definition: IConvertible.cs:9
static TimeZoneInfo Local
Gets a T:System.TimeZoneInfo object that represents the local time zone.
DateTime AddSeconds(double value)
Returns a new T:System.DateTime that adds the specified number of seconds to the value of this instan...
Definition: DateTime.cs:816
Provides a formatter-friendly mechanism for parsing the data in T:System.Runtime.Serialization....
static DateTime operator -(DateTime d, TimeSpan t)
Subtracts a specified time interval from a specified date and time and returns a new date and time.
Definition: DateTime.cs:1663
DateTimeStyles
Defines the formatting options that customize string parsing for some date and time parsing methods.
Provides functionality to format the value of an object into a string representation.
Definition: IFormattable.cs:8
void GetObjectData(SerializationInfo info, StreamingContext context)
Populates a T:System.Runtime.Serialization.SerializationInfo with the data needed to serialize the ta...
static bool operator >(DateTime t1, DateTime t2)
Determines whether one specified T:System.DateTime is later than another specified T:System....
Definition: DateTime.cs:1734
DateTime AddTicks(long value)
Returns a new T:System.DateTime that adds the specified number of ticks to the value of this instance...
Definition: DateTime.cs:826
uint ToUInt32(IFormatProvider provider)
Converts the value of this instance to an equivalent 32-bit unsigned integer using the specified cult...
static bool operator<=(DateTime t1, DateTime t2)
Determines whether one specified T:System.DateTime represents a date and time that is the same as or ...
Definition: DateTime.cs:1723
int Millisecond
Gets the milliseconds component of the date represented by this instance.
Definition: DateTime.cs:228
DayOfWeek
Specifies the day of the week.
Definition: DayOfWeek.cs:9
virtual DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond)
Returns a T:System.DateTime that is set to the specified date and time in the current era.
Definition: Calendar.cs:716
string [] GetDateTimeFormats()
Converts the value of this instance to all the string representations supported by the standard date ...
Definition: DateTime.cs:1753
long Ticks
Gets the number of ticks that represent the date and time of this instance.
Definition: DateTime.cs:315
DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond)
Initializes a new instance of the T:System.DateTime structure to the specified year,...
Definition: DateTime.cs:529
bool MoveNext()
Updates the enumerator to the next item.
static bool TryParse(string s, IFormatProvider provider, DateTimeStyles styles, out DateTime result)
Converts the specified string representation of a date and time to its T:System.DateTime equivalent u...
Definition: DateTime.cs:1598