mscorlib(4.0.0.0) API with additions
DateTimeOffset.cs
4 using System.Security;
5 
6 namespace System
7 {
10  [StructLayout(LayoutKind.Auto)]
11  [__DynamicallyInvokable]
13  {
14  internal const long MaxOffset = 504000000000L;
15 
16  internal const long MinOffset = -504000000000L;
17 
18  private const long UnixEpochTicks = 621355968000000000L;
19 
20  private const long UnixEpochSeconds = 62135596800L;
21 
22  private const long UnixEpochMilliseconds = 62135596800000L;
23 
25  [__DynamicallyInvokable]
26  public static readonly DateTimeOffset MinValue = new DateTimeOffset(0L, TimeSpan.Zero);
27 
31  [__DynamicallyInvokable]
32  public static readonly DateTimeOffset MaxValue = new DateTimeOffset(3155378975999999999L, TimeSpan.Zero);
33 
34  private DateTime m_dateTime;
35 
36  private short m_offsetMinutes;
37 
40  [__DynamicallyInvokable]
41  public static DateTimeOffset Now
42  {
43  [__DynamicallyInvokable]
44  get
45  {
46  return new DateTimeOffset(DateTime.Now);
47  }
48  }
49 
52  [__DynamicallyInvokable]
53  public static DateTimeOffset UtcNow
54  {
55  [__DynamicallyInvokable]
56  get
57  {
58  return new DateTimeOffset(DateTime.UtcNow);
59  }
60  }
61 
64  [__DynamicallyInvokable]
65  public DateTime DateTime
66  {
67  [__DynamicallyInvokable]
68  get
69  {
70  return ClockDateTime;
71  }
72  }
73 
76  [__DynamicallyInvokable]
77  public DateTime UtcDateTime
78  {
79  [__DynamicallyInvokable]
80  get
81  {
82  return DateTime.SpecifyKind(m_dateTime, DateTimeKind.Utc);
83  }
84  }
85 
88  [__DynamicallyInvokable]
89  public DateTime LocalDateTime
90  {
91  [__DynamicallyInvokable]
92  get
93  {
94  return UtcDateTime.ToLocalTime();
95  }
96  }
97 
98  private DateTime ClockDateTime => new DateTime((m_dateTime + Offset).Ticks, DateTimeKind.Unspecified);
99 
102  [__DynamicallyInvokable]
103  public DateTime Date
104  {
105  [__DynamicallyInvokable]
106  get
107  {
108  return ClockDateTime.Date;
109  }
110  }
111 
114  [__DynamicallyInvokable]
115  public int Day
116  {
117  [__DynamicallyInvokable]
118  get
119  {
120  return ClockDateTime.Day;
121  }
122  }
123 
126  [__DynamicallyInvokable]
127  public DayOfWeek DayOfWeek
128  {
129  [__DynamicallyInvokable]
130  get
131  {
132  return ClockDateTime.DayOfWeek;
133  }
134  }
135 
138  [__DynamicallyInvokable]
139  public int DayOfYear
140  {
141  [__DynamicallyInvokable]
142  get
143  {
144  return ClockDateTime.DayOfYear;
145  }
146  }
147 
150  [__DynamicallyInvokable]
151  public int Hour
152  {
153  [__DynamicallyInvokable]
154  get
155  {
156  return ClockDateTime.Hour;
157  }
158  }
159 
162  [__DynamicallyInvokable]
163  public int Millisecond
164  {
165  [__DynamicallyInvokable]
166  get
167  {
168  return ClockDateTime.Millisecond;
169  }
170  }
171 
174  [__DynamicallyInvokable]
175  public int Minute
176  {
177  [__DynamicallyInvokable]
178  get
179  {
180  return ClockDateTime.Minute;
181  }
182  }
183 
186  [__DynamicallyInvokable]
187  public int Month
188  {
189  [__DynamicallyInvokable]
190  get
191  {
192  return ClockDateTime.Month;
193  }
194  }
195 
198  [__DynamicallyInvokable]
199  public TimeSpan Offset
200  {
201  [__DynamicallyInvokable]
202  get
203  {
204  return new TimeSpan(0, m_offsetMinutes, 0);
205  }
206  }
207 
210  [__DynamicallyInvokable]
211  public int Second
212  {
213  [__DynamicallyInvokable]
214  get
215  {
216  return ClockDateTime.Second;
217  }
218  }
219 
222  [__DynamicallyInvokable]
223  public long Ticks
224  {
225  [__DynamicallyInvokable]
226  get
227  {
228  return ClockDateTime.Ticks;
229  }
230  }
231 
234  [__DynamicallyInvokable]
235  public long UtcTicks
236  {
237  [__DynamicallyInvokable]
238  get
239  {
240  return UtcDateTime.Ticks;
241  }
242  }
243 
246  [__DynamicallyInvokable]
247  public TimeSpan TimeOfDay
248  {
249  [__DynamicallyInvokable]
250  get
251  {
252  return ClockDateTime.TimeOfDay;
253  }
254  }
255 
258  [__DynamicallyInvokable]
259  public int Year
260  {
261  [__DynamicallyInvokable]
262  get
263  {
264  return ClockDateTime.Year;
265  }
266  }
267 
276  [__DynamicallyInvokable]
277  public DateTimeOffset(long ticks, TimeSpan offset)
278  {
279  m_offsetMinutes = ValidateOffset(offset);
280  DateTime dateTime = new DateTime(ticks);
281  m_dateTime = ValidateDate(dateTime, offset);
282  }
283 
287  [__DynamicallyInvokable]
288  public DateTimeOffset(DateTime dateTime)
289  {
290  TimeSpan offset = (dateTime.Kind != DateTimeKind.Utc) ? TimeZoneInfo.GetLocalUtcOffset(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime) : new TimeSpan(0L);
291  m_offsetMinutes = ValidateOffset(offset);
292  m_dateTime = ValidateDate(dateTime, offset);
293  }
294 
305  [__DynamicallyInvokable]
306  public DateTimeOffset(DateTime dateTime, TimeSpan offset)
307  {
308  if (dateTime.Kind == DateTimeKind.Local)
309  {
310  if (offset != TimeZoneInfo.GetLocalUtcOffset(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime))
311  {
312  throw new ArgumentException(Environment.GetResourceString("Argument_OffsetLocalMismatch"), "offset");
313  }
314  }
315  else if (dateTime.Kind == DateTimeKind.Utc && offset != TimeSpan.Zero)
316  {
317  throw new ArgumentException(Environment.GetResourceString("Argument_OffsetUtcMismatch"), "offset");
318  }
319  m_offsetMinutes = ValidateOffset(offset);
320  m_dateTime = ValidateDate(dateTime, offset);
321  }
322 
341  [__DynamicallyInvokable]
342  public DateTimeOffset(int year, int month, int day, int hour, int minute, int second, TimeSpan offset)
343  {
344  m_offsetMinutes = ValidateOffset(offset);
345  m_dateTime = ValidateDate(new DateTime(year, month, day, hour, minute, second), offset);
346  }
347 
368  [__DynamicallyInvokable]
369  public DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, TimeSpan offset)
370  {
371  m_offsetMinutes = ValidateOffset(offset);
372  m_dateTime = ValidateDate(new DateTime(year, month, day, hour, minute, second, millisecond), offset);
373  }
374 
398  public DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar, TimeSpan offset)
399  {
400  m_offsetMinutes = ValidateOffset(offset);
401  m_dateTime = ValidateDate(new DateTime(year, month, day, hour, minute, second, millisecond, calendar), offset);
402  }
403 
411  [__DynamicallyInvokable]
413  {
414  return new DateTimeOffset((m_dateTime + offset).Ticks, offset);
415  }
416 
421  [__DynamicallyInvokable]
422  public DateTimeOffset Add(TimeSpan timeSpan)
423  {
424  return new DateTimeOffset(ClockDateTime.Add(timeSpan), Offset);
425  }
426 
431  [__DynamicallyInvokable]
432  public DateTimeOffset AddDays(double days)
433  {
434  return new DateTimeOffset(ClockDateTime.AddDays(days), Offset);
435  }
436 
441  [__DynamicallyInvokable]
442  public DateTimeOffset AddHours(double hours)
443  {
444  return new DateTimeOffset(ClockDateTime.AddHours(hours), Offset);
445  }
446 
451  [__DynamicallyInvokable]
452  public DateTimeOffset AddMilliseconds(double milliseconds)
453  {
454  return new DateTimeOffset(ClockDateTime.AddMilliseconds(milliseconds), Offset);
455  }
456 
461  [__DynamicallyInvokable]
462  public DateTimeOffset AddMinutes(double minutes)
463  {
464  return new DateTimeOffset(ClockDateTime.AddMinutes(minutes), Offset);
465  }
466 
471  [__DynamicallyInvokable]
472  public DateTimeOffset AddMonths(int months)
473  {
474  return new DateTimeOffset(ClockDateTime.AddMonths(months), Offset);
475  }
476 
481  [__DynamicallyInvokable]
482  public DateTimeOffset AddSeconds(double seconds)
483  {
484  return new DateTimeOffset(ClockDateTime.AddSeconds(seconds), Offset);
485  }
486 
491  [__DynamicallyInvokable]
492  public DateTimeOffset AddTicks(long ticks)
493  {
494  return new DateTimeOffset(ClockDateTime.AddTicks(ticks), Offset);
495  }
496 
501  [__DynamicallyInvokable]
502  public DateTimeOffset AddYears(int years)
503  {
504  return new DateTimeOffset(ClockDateTime.AddYears(years), Offset);
505  }
506 
514  [__DynamicallyInvokable]
515  public static int Compare(DateTimeOffset first, DateTimeOffset second)
516  {
517  return DateTime.Compare(first.UtcDateTime, second.UtcDateTime);
518  }
519 
523  [__DynamicallyInvokable]
524  int IComparable.CompareTo(object obj)
525  {
526  if (obj == null)
527  {
528  return 1;
529  }
530  if (!(obj is DateTimeOffset))
531  {
532  throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDateTimeOffset"));
533  }
534  DateTime utcDateTime = ((DateTimeOffset)obj).UtcDateTime;
535  DateTime utcDateTime2 = UtcDateTime;
536  if (utcDateTime2 > utcDateTime)
537  {
538  return 1;
539  }
540  if (utcDateTime2 < utcDateTime)
541  {
542  return -1;
543  }
544  return 0;
545  }
546 
550  [__DynamicallyInvokable]
551  public int CompareTo(DateTimeOffset other)
552  {
553  DateTime utcDateTime = other.UtcDateTime;
554  DateTime utcDateTime2 = UtcDateTime;
555  if (utcDateTime2 > utcDateTime)
556  {
557  return 1;
558  }
559  if (utcDateTime2 < utcDateTime)
560  {
561  return -1;
562  }
563  return 0;
564  }
565 
570  [__DynamicallyInvokable]
571  public override bool Equals(object obj)
572  {
573  if (obj is DateTimeOffset)
574  {
576  }
577  return false;
578  }
579 
584  [__DynamicallyInvokable]
585  public bool Equals(DateTimeOffset other)
586  {
587  return UtcDateTime.Equals(other.UtcDateTime);
588  }
589 
594  [__DynamicallyInvokable]
595  public bool EqualsExact(DateTimeOffset other)
596  {
597  if (ClockDateTime == other.ClockDateTime && Offset == other.Offset)
598  {
599  return ClockDateTime.Kind == other.ClockDateTime.Kind;
600  }
601  return false;
602  }
603 
609  [__DynamicallyInvokable]
610  public static bool Equals(DateTimeOffset first, DateTimeOffset second)
611  {
612  return DateTime.Equals(first.UtcDateTime, second.UtcDateTime);
613  }
614 
621  [__DynamicallyInvokable]
622  public static DateTimeOffset FromFileTime(long fileTime)
623  {
624  return new DateTimeOffset(DateTime.FromFileTime(fileTime));
625  }
626 
633  [__DynamicallyInvokable]
634  public static DateTimeOffset FromUnixTimeSeconds(long seconds)
635  {
636  if (seconds < -62135596800L || seconds > 253402300799L)
637  {
638  throw new ArgumentOutOfRangeException("seconds", string.Format(Environment.GetResourceString("ArgumentOutOfRange_Range"), -62135596800L, 253402300799L));
639  }
640  long ticks = seconds * 10000000 + 621355968000000000L;
641  return new DateTimeOffset(ticks, TimeSpan.Zero);
642  }
643 
650  [__DynamicallyInvokable]
651  public static DateTimeOffset FromUnixTimeMilliseconds(long milliseconds)
652  {
653  if (milliseconds < -62135596800000L || milliseconds > 253402300799999L)
654  {
655  throw new ArgumentOutOfRangeException("milliseconds", string.Format(Environment.GetResourceString("ArgumentOutOfRange_Range"), -62135596800000L, 253402300799999L));
656  }
657  long ticks = milliseconds * 10000 + 621355968000000000L;
658  return new DateTimeOffset(ticks, TimeSpan.Zero);
659  }
660 
664  {
665  try
666  {
667  m_offsetMinutes = ValidateOffset(Offset);
668  m_dateTime = ValidateDate(ClockDateTime, Offset);
669  }
670  catch (ArgumentException innerException)
671  {
672  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"), innerException);
673  }
674  }
675 
680  [SecurityCritical]
682  {
683  if (info == null)
684  {
685  throw new ArgumentNullException("info");
686  }
687  info.AddValue("DateTime", m_dateTime);
688  info.AddValue("OffsetMinutes", m_offsetMinutes);
689  }
690 
691  private DateTimeOffset(SerializationInfo info, StreamingContext context)
692  {
693  if (info == null)
694  {
695  throw new ArgumentNullException("info");
696  }
697  m_dateTime = (DateTime)info.GetValue("DateTime", typeof(DateTime));
698  m_offsetMinutes = (short)info.GetValue("OffsetMinutes", typeof(short));
699  }
700 
703  [__DynamicallyInvokable]
704  public override int GetHashCode()
705  {
706  return UtcDateTime.GetHashCode();
707  }
708 
718  [__DynamicallyInvokable]
719  public static DateTimeOffset Parse(string input)
720  {
721  TimeSpan offset;
722  return new DateTimeOffset(DateTimeParse.Parse(input, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None, out offset).Ticks, offset);
723  }
724 
735  [__DynamicallyInvokable]
736  public static DateTimeOffset Parse(string input, IFormatProvider formatProvider)
737  {
738  return Parse(input, formatProvider, DateTimeStyles.None);
739  }
740 
755  [__DynamicallyInvokable]
756  public static DateTimeOffset Parse(string input, IFormatProvider formatProvider, DateTimeStyles styles)
757  {
758  styles = ValidateStyles(styles, "styles");
759  TimeSpan offset;
760  return new DateTimeOffset(DateTimeParse.Parse(input, DateTimeFormatInfo.GetInstance(formatProvider), styles, out offset).Ticks, offset);
761  }
762 
777  [__DynamicallyInvokable]
778  public static DateTimeOffset ParseExact(string input, string format, IFormatProvider formatProvider)
779  {
780  return ParseExact(input, format, formatProvider, DateTimeStyles.None);
781  }
782 
798  [__DynamicallyInvokable]
799  public static DateTimeOffset ParseExact(string input, string format, IFormatProvider formatProvider, DateTimeStyles styles)
800  {
801  styles = ValidateStyles(styles, "styles");
802  TimeSpan offset;
803  return new DateTimeOffset(DateTimeParse.ParseExact(input, format, DateTimeFormatInfo.GetInstance(formatProvider), styles, out offset).Ticks, offset);
804  }
805 
820  [__DynamicallyInvokable]
821  public static DateTimeOffset ParseExact(string input, string[] formats, IFormatProvider formatProvider, DateTimeStyles styles)
822  {
823  styles = ValidateStyles(styles, "styles");
824  TimeSpan offset;
825  return new DateTimeOffset(DateTimeParse.ParseExactMultiple(input, formats, DateTimeFormatInfo.GetInstance(formatProvider), styles, out offset).Ticks, offset);
826  }
827 
831  [__DynamicallyInvokable]
833  {
834  return UtcDateTime.Subtract(value.UtcDateTime);
835  }
836 
841  [__DynamicallyInvokable]
843  {
844  return new DateTimeOffset(ClockDateTime.Subtract(value), Offset);
845  }
846 
850  [__DynamicallyInvokable]
851  public long ToFileTime()
852  {
853  return UtcDateTime.ToFileTime();
854  }
855 
858  [__DynamicallyInvokable]
859  public long ToUnixTimeSeconds()
860  {
861  long num = UtcDateTime.Ticks / 10000000;
862  return num - 62135596800L;
863  }
864 
867  [__DynamicallyInvokable]
869  {
870  long num = UtcDateTime.Ticks / 10000;
871  return num - 62135596800000L;
872  }
873 
876  [__DynamicallyInvokable]
878  {
879  return ToLocalTime(throwOnOverflow: false);
880  }
881 
882  internal DateTimeOffset ToLocalTime(bool throwOnOverflow)
883  {
884  return new DateTimeOffset(UtcDateTime.ToLocalTime(throwOnOverflow));
885  }
886 
890  [__DynamicallyInvokable]
891  public override string ToString()
892  {
893  return DateTimeFormat.Format(ClockDateTime, null, DateTimeFormatInfo.CurrentInfo, Offset);
894  }
895 
902  [__DynamicallyInvokable]
903  public string ToString(string format)
904  {
905  return DateTimeFormat.Format(ClockDateTime, format, DateTimeFormatInfo.CurrentInfo, Offset);
906  }
907 
912  [__DynamicallyInvokable]
913  public string ToString(IFormatProvider formatProvider)
914  {
915  return DateTimeFormat.Format(ClockDateTime, null, DateTimeFormatInfo.GetInstance(formatProvider), Offset);
916  }
917 
925  [__DynamicallyInvokable]
926  public string ToString(string format, IFormatProvider formatProvider)
927  {
928  return DateTimeFormat.Format(ClockDateTime, format, DateTimeFormatInfo.GetInstance(formatProvider), Offset);
929  }
930 
933  [__DynamicallyInvokable]
935  {
936  return new DateTimeOffset(UtcDateTime);
937  }
938 
944  [__DynamicallyInvokable]
945  public static bool TryParse(string input, out DateTimeOffset result)
946  {
947  DateTime result2;
948  TimeSpan offset;
949  bool result3 = DateTimeParse.TryParse(input, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None, out result2, out offset);
950  result = new DateTimeOffset(result2.Ticks, offset);
951  return result3;
952  }
953 
965  [__DynamicallyInvokable]
966  public static bool TryParse(string input, IFormatProvider formatProvider, DateTimeStyles styles, out DateTimeOffset result)
967  {
968  styles = ValidateStyles(styles, "styles");
969  DateTime result2;
970  TimeSpan offset;
971  bool result3 = DateTimeParse.TryParse(input, DateTimeFormatInfo.GetInstance(formatProvider), styles, out result2, out offset);
972  result = new DateTimeOffset(result2.Ticks, offset);
973  return result3;
974  }
975 
988  [__DynamicallyInvokable]
989  public static bool TryParseExact(string input, string format, IFormatProvider formatProvider, DateTimeStyles styles, out DateTimeOffset result)
990  {
991  styles = ValidateStyles(styles, "styles");
992  DateTime result2;
993  TimeSpan offset;
994  bool result3 = DateTimeParse.TryParseExact(input, format, DateTimeFormatInfo.GetInstance(formatProvider), styles, out result2, out offset);
995  result = new DateTimeOffset(result2.Ticks, offset);
996  return result3;
997  }
998 
1011  [__DynamicallyInvokable]
1012  public static bool TryParseExact(string input, string[] formats, IFormatProvider formatProvider, DateTimeStyles styles, out DateTimeOffset result)
1013  {
1014  styles = ValidateStyles(styles, "styles");
1015  DateTime result2;
1016  TimeSpan offset;
1017  bool result3 = DateTimeParse.TryParseExactMultiple(input, formats, DateTimeFormatInfo.GetInstance(formatProvider), styles, out result2, out offset);
1018  result = new DateTimeOffset(result2.Ticks, offset);
1019  return result3;
1020  }
1021 
1022  private static short ValidateOffset(TimeSpan offset)
1023  {
1024  long ticks = offset.Ticks;
1025  if (ticks % 600000000 != 0L)
1026  {
1027  throw new ArgumentException(Environment.GetResourceString("Argument_OffsetPrecision"), "offset");
1028  }
1029  if (ticks < -504000000000L || ticks > 504000000000L)
1030  {
1031  throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("Argument_OffsetOutOfRange"));
1032  }
1033  return (short)(offset.Ticks / 600000000);
1034  }
1035 
1036  private static DateTime ValidateDate(DateTime dateTime, TimeSpan offset)
1037  {
1038  long num = dateTime.Ticks - offset.Ticks;
1039  if (num < 0 || num > 3155378975999999999L)
1040  {
1041  throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("Argument_UTCOutOfRange"));
1042  }
1043  return new DateTime(num, DateTimeKind.Unspecified);
1044  }
1045 
1046  private static DateTimeStyles ValidateStyles(DateTimeStyles style, string parameterName)
1047  {
1048  if ((style & ~(DateTimeStyles.AllowLeadingWhite | DateTimeStyles.AllowTrailingWhite | DateTimeStyles.AllowInnerWhite | DateTimeStyles.NoCurrentDateDefault | DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeLocal | DateTimeStyles.AssumeUniversal | DateTimeStyles.RoundtripKind)) != 0)
1049  {
1050  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidDateTimeStyles"), parameterName);
1051  }
1052  if ((style & DateTimeStyles.AssumeLocal) != 0 && (style & DateTimeStyles.AssumeUniversal) != 0)
1053  {
1054  throw new ArgumentException(Environment.GetResourceString("Argument_ConflictingDateTimeStyles"), parameterName);
1055  }
1056  if ((style & DateTimeStyles.NoCurrentDateDefault) != 0)
1057  {
1058  throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeOffsetInvalidDateTimeStyles"), parameterName);
1059  }
1060  style &= ~DateTimeStyles.RoundtripKind;
1061  style &= ~DateTimeStyles.AssumeLocal;
1062  return style;
1063  }
1064 
1069  [__DynamicallyInvokable]
1070  public static implicit operator DateTimeOffset(DateTime dateTime)
1071  {
1072  return new DateTimeOffset(dateTime);
1073  }
1074 
1080  [__DynamicallyInvokable]
1081  public static DateTimeOffset operator +(DateTimeOffset dateTimeOffset, TimeSpan timeSpan)
1082  {
1083  return new DateTimeOffset(dateTimeOffset.ClockDateTime + timeSpan, dateTimeOffset.Offset);
1084  }
1085 
1091  [__DynamicallyInvokable]
1092  public static DateTimeOffset operator -(DateTimeOffset dateTimeOffset, TimeSpan timeSpan)
1093  {
1094  return new DateTimeOffset(dateTimeOffset.ClockDateTime - timeSpan, dateTimeOffset.Offset);
1095  }
1096 
1101  [__DynamicallyInvokable]
1103  {
1104  return left.UtcDateTime - right.UtcDateTime;
1105  }
1106 
1112  [__DynamicallyInvokable]
1113  public static bool operator ==(DateTimeOffset left, DateTimeOffset right)
1114  {
1115  return left.UtcDateTime == right.UtcDateTime;
1116  }
1117 
1123  [__DynamicallyInvokable]
1124  public static bool operator !=(DateTimeOffset left, DateTimeOffset right)
1125  {
1126  return left.UtcDateTime != right.UtcDateTime;
1127  }
1128 
1134  [__DynamicallyInvokable]
1135  public static bool operator <(DateTimeOffset left, DateTimeOffset right)
1136  {
1137  return left.UtcDateTime < right.UtcDateTime;
1138  }
1139 
1145  [__DynamicallyInvokable]
1146  public static bool operator <=(DateTimeOffset left, DateTimeOffset right)
1147  {
1148  return left.UtcDateTime <= right.UtcDateTime;
1149  }
1150 
1156  [__DynamicallyInvokable]
1157  public static bool operator >(DateTimeOffset left, DateTimeOffset right)
1158  {
1159  return left.UtcDateTime > right.UtcDateTime;
1160  }
1161 
1167  [__DynamicallyInvokable]
1168  public static bool operator >=(DateTimeOffset left, DateTimeOffset right)
1169  {
1170  return left.UtcDateTime >= right.UtcDateTime;
1171  }
1172  }
1173 }
Represents any time zone in the world.
Definition: TimeZoneInfo.cs:20
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
int Day
Gets the day of the month represented by the current T:System.DateTimeOffset object.
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 bool TryParseExact(string input, string format, IFormatProvider formatProvider, DateTimeStyles styles, out DateTimeOffset result)
Converts the specified string representation of a date and time to its T:System.DateTimeOffset equiva...
static DateTimeOffset Parse(string input, IFormatProvider formatProvider)
Converts the specified string representation of a date and time to its T:System.DateTimeOffset equiva...
DateTimeOffset Subtract(TimeSpan value)
Subtracts a specified time interval from the current T:System.DateTimeOffset object.
Represents a point in time, typically expressed as a date and time of day, relative to Coordinated Un...
static DateTime FromFileTime(long fileTime)
Converts the specified Windows file time to an equivalent local time.
Definition: DateTime.cs:1092
static readonly DateTimeOffset MinValue
Represents the earliest possible T:System.DateTimeOffset value. This field is read-only.
DateTimeOffset ToOffset(TimeSpan offset)
Converts the value of the current T:System.DateTimeOffset object to the date and time specified by an...
DateTimeOffset(long ticks, TimeSpan offset)
Initializes a new instance of the T:System.DateTimeOffset structure using the specified number of tic...
long ToFileTime()
Converts the value of the current T:System.DateTimeOffset object to a Windows file time.
Indicates that a class is to be notified when deserialization of the entire object graph has been com...
LayoutKind
Controls the layout of an object when exported to unmanaged code.
Definition: LayoutKind.cs:7
Definition: __Canon.cs:3
int Minute
Gets the minute component of the time represented by the current T:System.DateTimeOffset object.
static DateTimeOffset Parse(string input, IFormatProvider formatProvider, DateTimeStyles styles)
Converts the specified string representation of a date and time to its T:System.DateTimeOffset equiva...
static DateTimeOffset FromFileTime(long fileTime)
Converts the specified Windows file time to an equivalent local time.
The exception that is thrown when the value of an argument is outside the allowable range of values a...
long ToUnixTimeMilliseconds()
Returns the number of milliseconds that have elapsed since 1970-01-01T00:00:00.000Z.
static bool TryParseExact(string input, string format, IFormatProvider formatProvider, out TimeSpan result)
Converts the string representation of a time interval to its T:System.TimeSpan equivalent by using th...
Definition: TimeSpan.cs:698
int CompareTo(DateTimeOffset other)
Compares the current T:System.DateTimeOffset object to a specified T:System.DateTimeOffset object and...
static DateTimeOffset operator+(DateTimeOffset dateTimeOffset, TimeSpan timeSpan)
Adds a specified time interval to a T:System.DateTimeOffset object that has a specified date and time...
Provides a mechanism for retrieving an object to control formatting.
DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar, TimeSpan offset)
Initializes a new instance of the T:System.DateTimeOffset structure using the specified year,...
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
DayOfWeek DayOfWeek
Gets the day of the week represented by this instance.
Definition: DateTime.cs:172
TimeSpan TimeOfDay
Gets the time of day for the current T:System.DateTimeOffset object.
override bool Equals(object obj)
Determines whether a T:System.DateTimeOffset object represents the same point in time as a specified ...
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-...
Defines a generalized type-specific comparison method that a value type or class implements to order ...
Definition: IComparable.cs:8
DateTimeOffset ToUniversalTime()
Converts the current T:System.DateTimeOffset object to a T:System.DateTimeOffset value that represent...
int Second
Gets the seconds component of the date represented by this instance.
Definition: DateTime.cs:303
DateTimeOffset AddMonths(int months)
Returns a new T:System.DateTimeOffset object that adds a specified number of months to the value of t...
DateTime ToLocalTime()
Converts the value of the current T:System.DateTime object to local time.
Definition: DateTime.cs:1460
long Ticks
Gets the number of ticks that represents the date and time of the current T:System....
int Hour
Gets the hour component of the date represented by this instance.
Definition: DateTime.cs:196
static DateTimeOffset FromUnixTimeSeconds(long seconds)
Converts a Unix time expressed as the number of seconds that have elapsed since 1970-01-01T00:00:00Z ...
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
static bool TryParseExact(string input, string[] formats, IFormatProvider formatProvider, DateTimeStyles styles, out DateTimeOffset result)
Converts the specified string representation of a date and time to its T:System.DateTimeOffset equiva...
int Year
Gets the year component of the date represented by the current T:System.DateTimeOffset object.
static bool TryParse(string input, out DateTimeOffset result)
Tries to converts a specified string representation of a date and time to its T:System....
DateTimeOffset(DateTime dateTime, TimeSpan offset)
Initializes a new instance of the T:System.DateTimeOffset structure using the specified T:System....
DateTimeOffset AddHours(double hours)
Returns a new T:System.DateTimeOffset object that adds a specified number of whole and fractional hou...
DateTimeKind Kind
Gets a value that indicates whether the time represented by this instance is based on local time,...
Definition: DateTime.cs:208
DateTime DateTime
Gets a T:System.DateTime value that represents the date and time of the current T:System....
bool Equals(DateTimeOffset other)
Determines whether the current T:System.DateTimeOffset object represents the same point in time as a ...
static TimeSpan operator -(DateTimeOffset left, DateTimeOffset right)
Subtracts one T:System.DateTimeOffset object from another and yields a time interval.
TimeSpan Offset
Gets the time's offset from Coordinated Universal Time (UTC).
void OnDeserialization(object sender)
Runs when the entire object graph has been deserialized.
static bool TryParse(string input, IFormatProvider formatProvider, DateTimeStyles styles, out DateTimeOffset result)
Tries to convert a specified string representation of a date and time to its T:System....
string ToString(IFormatProvider formatProvider)
Converts the value of the current T:System.DateTimeOffset object to its equivalent string representat...
DateTimeOffset(DateTime dateTime)
Initializes a new instance of the T:System.DateTimeOffset structure using the specified T:System....
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
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
int Minute
Gets the minute component of the date represented by this instance.
Definition: DateTime.cs:240
static bool TryParse(string s, out TimeSpan result)
Converts the string representation of a time interval to its T:System.TimeSpan equivalent and returns...
Definition: TimeSpan.cs:673
DateTime Date
Gets the date component of this instance.
Definition: DateTime.cs:147
DateTime Date
Gets a T:System.DateTime value that represents the date component of the current T:System....
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
DateTimeOffset AddTicks(long ticks)
Returns a new T:System.DateTimeOffset object that adds a specified number of ticks to the value of th...
override bool Equals(object value)
Returns a value indicating whether this instance is equal to a specified object.
Definition: DateTime.cs:999
static DateTimeFormatInfo CurrentInfo
Gets a read-only T:System.Globalization.DateTimeFormatInfo object that formats values based on the cu...
DateTime LocalDateTime
Gets a T:System.DateTime value that represents the local date and time of the current T:System....
static DateTimeOffset ParseExact(string input, string format, IFormatProvider formatProvider)
Converts the specified string representation of a date and time to its T:System.DateTimeOffset equiva...
DateTimeOffset AddSeconds(double seconds)
Returns a new T:System.DateTimeOffset object that adds a specified number of whole and fractional sec...
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 bool operator >=(DateTimeOffset left, DateTimeOffset right)
Determines whether one specified T:System.DateTimeOffset object is greater than or equal to a second ...
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
static DateTimeOffset UtcNow
Gets a T:System.DateTimeOffset object whose date and time are set to the current Coordinated Universa...
static readonly TimeSpan Zero
Represents the zero T:System.TimeSpan value. This field is read-only.
Definition: TimeSpan.cs:64
static bool Equals(DateTimeOffset first, DateTimeOffset second)
Determines whether two specified T:System.DateTimeOffset objects represent the same point in time.
int Day
Gets the day of the month represented by this instance.
Definition: DateTime.cs:160
override string ToString()
Converts the value of the current T:System.DateTimeOffset object to its equivalent string representat...
static DateTimeOffset FromUnixTimeMilliseconds(long milliseconds)
Converts a Unix time expressed as the number of milliseconds that have elapsed since 1970-01-01T00:00...
string ToString(string format, IFormatProvider formatProvider)
Converts the value of the current T:System.DateTimeOffset object to its equivalent string representat...
DateTimeOffset AddMinutes(double minutes)
Returns a new T:System.DateTimeOffset object that adds a specified number of whole and fractional min...
int Millisecond
Gets the millisecond component of the time represented by the current T:System.DateTimeOffset object.
static bool operator==(DateTimeOffset left, DateTimeOffset right)
Determines whether two specified T:System.DateTimeOffset objects represent the same point in time.
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
int Hour
Gets the hour component of the time represented by the current T:System.DateTimeOffset object.
int DayOfYear
Gets the day of the year represented by the current T:System.DateTimeOffset object.
The exception that is thrown when one of the arguments provided to a method is not valid.
static DateTimeOffset ParseExact(string input, string format, IFormatProvider formatProvider, DateTimeStyles styles)
Converts the specified string representation of a date and time to its T:System.DateTimeOffset equiva...
DateTimeOffset AddDays(double days)
Returns a new T:System.DateTimeOffset object that adds a specified number of whole and fractional day...
static DateTimeOffset operator -(DateTimeOffset dateTimeOffset, TimeSpan timeSpan)
Subtracts a specified time interval from a specified date and time, and yields a new date and time.
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
static DateTimeOffset ParseExact(string input, string[] formats, IFormatProvider formatProvider, DateTimeStyles styles)
Converts the specified string representation of a date and time to its T:System.DateTimeOffset equiva...
TimeSpan Subtract(DateTimeOffset value)
Subtracts a T:System.DateTimeOffset value that represents a specific date and time from the current T...
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
DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, TimeSpan offset)
Initializes a new instance of the T:System.DateTimeOffset structure using the specified year,...
DateTimeKind
Specifies whether a T:System.DateTime object represents a local time, a Coordinated Universal Time (U...
Definition: DateTimeKind.cs:9
static readonly DateTimeOffset MaxValue
Represents the greatest possible value of T:System.DateTimeOffset. This field is read-only.
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
bool EqualsExact(DateTimeOffset other)
Determines whether the current T:System.DateTimeOffset object represents the same time and has the sa...
DateTimeOffset Add(TimeSpan timeSpan)
Returns a new T:System.DateTimeOffset object that adds a specified time interval to the value of this...
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 Now
Gets a T:System.DateTime object that is set to the current date and time on this computer,...
Definition: DateTime.cs:264
DateTimeOffset AddYears(int years)
Returns a new T:System.DateTimeOffset object that adds a specified number of years to the value of th...
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 bool operator >(DateTimeOffset left, DateTimeOffset right)
Determines whether one specified T:System.DateTimeOffset object is greater than (or later than) a sec...
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
DateTimeOffset ToLocalTime()
Converts the current T:System.DateTimeOffset object to a T:System.DateTimeOffset object that represen...
string ToString(string format)
Converts the value of the current T:System.DateTimeOffset object to its equivalent string representat...
static bool operator<=(DateTimeOffset left, DateTimeOffset right)
Determines whether one specified T:System.DateTimeOffset object is less than a second specified T:Sys...
static DateTimeOffset Now
Gets a T:System.DateTimeOffset object that is set to the current date and time on the current compute...
static bool operator<(DateTimeOffset left, DateTimeOffset right)
Determines whether one specified T:System.DateTimeOffset object is less than a second specified T:Sys...
static DateTimeOffset Parse(string input)
Converts the specified string representation of a date, time, and offset to its T:System....
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
DateTimeOffset AddMilliseconds(double milliseconds)
Returns a new T:System.DateTimeOffset object that adds a specified number of milliseconds to the valu...
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...
DateTime UtcDateTime
Gets a T:System.DateTime value that represents the Coordinated Universal Time (UTC) date and time of ...
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
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
override int GetHashCode()
Returns the hash code for the current T:System.DateTimeOffset object.
DateTimeOffset(int year, int month, int day, int hour, int minute, int second, TimeSpan offset)
Initializes a new instance of the T:System.DateTimeOffset structure using the specified year,...
long Ticks
Gets the number of ticks that represent the date and time of this instance.
Definition: DateTime.cs:315
int Second
Gets the second component of the clock time represented by the current T:System.DateTimeOffset object...
static bool operator !=(DateTimeOffset left, DateTimeOffset right)
Determines whether two specified T:System.DateTimeOffset objects refer to different points in time.
long ToUnixTimeSeconds()
Returns the number of seconds that have elapsed since 1970-01-01T00:00:00Z.
int Month
Gets the month component of the date represented by the current T:System.DateTimeOffset object.
long UtcTicks
Gets the number of ticks that represents the date and time of the current T:System....
static int Compare(DateTimeOffset first, DateTimeOffset second)
Compares two T:System.DateTimeOffset objects and indicates whether the first is earlier than the seco...