c++builde r时间日期函数大全,在头文件System.DateUtils.hpp,不过没有IncMonth,因为这个函数定义在System.SysUtils.hpp里头了,唉
date,dateTime
#include <System.DateUtils.hpp>
#include <System.SysUtils.hpp>
IncMonth
IsValidDateTime,IsValidDate,IsValidTime
TryEncodeDateTime,WithinPastMonths
DaySpan,DaysBetween,WeekSpan,WeeksBetween,MonthSpan,MonthsBetween,HourSpan
1 namespace System 2 { 3 namespace Dateutils 4 { 5 extern const Extended OneHour /*= 4.166667E-02*/; 6 extern const Extended OneMinute /*= 6.944444E-04*/; 7 extern const Extended OneSecond /*= 1.157407E-05*/; 8 extern const Extended OneMillisecond /*= 1.157407E-08*/; 9 extern const Extended EpochAsJulianDate /*= 2.415018E+06*/; 10 } /* namespace Dateutils */ 11 } /* namespace System */ 12 13 namespace System 14 { 15 namespace Dateutils 16 { 78 enum DECLSPEC_DENUM TLocalTimeType : unsigned char { lttStandard, lttDaylight, lttAmbiguous, lttInvalid }; 79 80 83 class PASCALIMPLEMENTATION TTimeZone : public TObject 84 { 85 typedef TObject inherited; 86 87 private: 88 static TTimeZone* FLocal; 89 90 private: 91 // __classmethod void __fastcall Create@(); 92 // __classmethod void __fastcall Destroy@(); 93 94 private: 95 UnicodeString __fastcall GetAbbreviationForNow(void); 96 UnicodeString __fastcall GetDisplayNameForNow(void); 97 __int64 __fastcall GetUtcOffsetInSeconds(const TDateTime ADateTime, const bool ForceDaylight); 98 Timespan::TTimeSpan __fastcall GetCurrentUtcOffset(void); 99 100 protected: 101 virtual void __fastcall DoGetOffsetsAndType(const TDateTime ADateTime, /* out */ __int64 &AOffset, /* out */ __int64 &ADstSave, /* out */ TLocalTimeType &AType) = 0 ; 102 virtual UnicodeString __fastcall DoGetDisplayName(const TDateTime ADateTime, const bool ForceDaylight) = 0 ; 103 virtual UnicodeString __fastcall DoGetID(void) = 0 ; 104 105 public: 106 Timespan::TTimeSpan __fastcall GetUtcOffset(const TDateTime ADateTime, const bool ForceDaylight = false); 107 TDateTime __fastcall ToUniversalTime(const TDateTime ADateTime, const bool ForceDaylight = false); 108 TDateTime __fastcall ToLocalTime(const TDateTime ADateTime); 109 UnicodeString __fastcall GetDisplayName(const TDateTime ADateTime, const bool ForceDaylight = false); 110 UnicodeString __fastcall GetAbbreviation(const TDateTime ADateTime, const bool ForceDaylight = false); 111 TLocalTimeType __fastcall GetLocalTimeType(const TDateTime ADateTime); 112 bool __fastcall IsStandardTime(const TDateTime ADateTime, const bool ForceDaylight = false); 113 bool __fastcall IsInvalidTime(const TDateTime ADateTime); 114 bool __fastcall IsAmbiguousTime(const TDateTime ADateTime); 115 bool __fastcall IsDaylightTime(const TDateTime ADateTime, const bool ForceDaylight = false); 116 __property UnicodeString ID = {read=DoGetID}; 117 __property UnicodeString DisplayName = {read=GetDisplayNameForNow}; 118 __property UnicodeString Abbreviation = {read=GetAbbreviationForNow}; 119 __property Timespan::TTimeSpan UtcOffset = {read=GetCurrentUtcOffset}; 120 /* static */ __property TTimeZone* Local = {read=FLocal}; 121 public: 122 /* TObject.Create */ inline __fastcall TTimeZone(void) : TObject() { } 123 /* TObject.Destroy */ inline __fastcall virtual ~TTimeZone(void) { } 124 125 }; 131 //-- var, const, procedure --------------------------------------------------- 132 static const Int8 DaysPerWeek = Int8(0x7); 133 static const Int8 WeeksPerFortnight = Int8(0x2); 134 static const Int8 MonthsPerYear = Int8(0xc); 135 static const Int8 YearsPerDecade = Int8(0xa); 136 static const Int8 YearsPerCentury = Int8(0x64); 137 static const Word YearsPerMillennium = Word(0x3e8); 138 static const Int8 DayMonday = Int8(0x1); 139 static const Int8 DayTuesday = Int8(0x2); 140 static const Int8 DayWednesday = Int8(0x3); 141 static const Int8 DayThursday = Int8(0x4); 142 static const Int8 DayFriday = Int8(0x5); 143 static const Int8 DaySaturday = Int8(0x6); 144 static const Int8 DaySunday = Int8(0x7); 145 static const Int8 MonthJanuary = Int8(0x1); 146 static const Int8 MonthFebruary = Int8(0x2); 147 static const Int8 MonthMarch = Int8(0x3); 148 static const Int8 MonthApril = Int8(0x4); 149 static const Int8 MonthMay = Int8(0x5); 150 static const Int8 MonthJune = Int8(0x6); 151 static const Int8 MonthJuly = Int8(0x7); 152 static const Int8 MonthAugust = Int8(0x8); 153 static const Int8 MonthSeptember = Int8(0x9); 154 static const Int8 MonthOctober = Int8(0xa); 155 static const Int8 MonthNovember = Int8(0xb); 156 static const Int8 MonthDecember = Int8(0xc); 157 static const __int64 EpochAsUnixDate = -0x0000000083ad2180LL; 158 StaticArray<Word, 2> DaysPerYear; 159 static const Word RecodeLeaveFieldAsIs = Word(0xffff); 160 double ApproxDaysPerMonth; 161 double ApproxDaysPerYear; 162 TDateTime __fastcall DateOf(const TDateTime AValue); 163 TDateTime __fastcall TimeOf(const TDateTime AValue); 164 bool __fastcall IsInLeapYear(const TDateTime AValue); 165 bool __fastcall IsPM(const TDateTime AValue); 166 bool __fastcall IsAM(const TDateTime AValue); 167 bool __fastcall IsValidDate(const Word AYear, const Word AMonth, const Word ADay); 168 bool __fastcall IsValidTime(const Word AHour, const Word AMinute, const Word ASecond, const Word AMilliSecond); 169 bool __fastcall IsValidDateTime(const Word AYear, const Word AMonth, const Word ADay, const Word AHour, const Word AMinute, const Word ASecond, const Word AMilliSecond); 170 bool __fastcall IsValidDateMonthWeek(const Word AYear, const Word AMonth, const Word AWeekOfMonth, const Word ADayOfWeek); 171 bool __fastcall IsValidDateDay(const Word AYear, const Word ADayOfYear); 172 bool __fastcall IsValidDateWeek(const Word AYear, const Word AWeekOfYear, const Word ADayOfWeek); 173 Word __fastcall DaysInYear(const TDateTime AValue); 174 Word __fastcall DaysInAYear(const Word AYear); 175 Word __fastcall DaysInMonth(const TDateTime AValue); 176 Word __fastcall DaysInAMonth(const Word AYear, const Word AMonth); 177 Word __fastcall WeeksInYear(const TDateTime AValue); 178 Word __fastcall WeeksInAYear(const Word AYear); 179 TDateTime __fastcall Today(void); 180 TDateTime __fastcall Yesterday(void); 181 TDateTime __fastcall Tomorrow(void); 182 bool __fastcall IsToday(const TDateTime AValue); 183 bool __fastcall IsSameDay(const TDateTime AValue, const TDateTime ABasis); 184 Word __fastcall YearOf(const TDateTime AValue); 185 Word __fastcall MonthOf(const TDateTime AValue); 186 Word __fastcall WeekOf(const TDateTime AValue); 187 Word __fastcall DayOf(const TDateTime AValue); 188 Word __fastcall HourOf(const TDateTime AValue); 189 Word __fastcall MinuteOf(const TDateTime AValue); 190 Word __fastcall SecondOf(const TDateTime AValue); 191 Word __fastcall MilliSecondOf(const TDateTime AValue); 192 TDateTime __fastcall StartOfTheYear(const TDateTime AValue); 193 TDateTime __fastcall EndOfTheYear(const TDateTime AValue); 194 TDateTime __fastcall StartOfTheMonth(const TDateTime AValue); 195 TDateTime __fastcall EndOfTheMonth(const TDateTime AValue); 196 TDateTime __fastcall StartOfTheWeek(const TDateTime AValue); 197 TDateTime __fastcall EndOfTheWeek(const TDateTime AValue); 198 TDateTime __fastcall StartOfTheDay(const TDateTime AValue); 199 TDateTime __fastcall EndOfTheDay(const TDateTime AValue); 200 TDateTime __fastcall StartOfAYear(const Word AYear); 201 TDateTime __fastcall EndOfAYear(const Word AYear); 202 TDateTime __fastcall StartOfAMonth(const Word AYear, const Word AMonth); 203 TDateTime __fastcall EndOfAMonth(const Word AYear, const Word AMonth); 204 TDateTime __fastcall StartOfAWeek(const Word AYear, const Word AWeekOfYear, const Word ADayOfWeek = (Word)(0x1)); 205 TDateTime __fastcall EndOfAWeek(const Word AYear, const Word AWeekOfYear, const Word ADayOfWeek = (Word)(0x7)); 206 TDateTime __fastcall StartOfADay(const Word AYear, const Word ADayOfYear)/* overload */; 207 TDateTime __fastcall EndOfADay(const Word AYear, const Word ADayOfYear)/* overload */; 208 TDateTime __fastcall StartOfADay(const Word AYear, const Word AMonth, const Word ADay)/* overload */; 209 TDateTime __fastcall EndOfADay(const Word AYear, const Word AMonth, const Word ADay)/* overload */; 210 Word __fastcall MonthOfTheYear(const TDateTime AValue); 211 Word __fastcall WeekOfTheYear(const TDateTime AValue)/* overload */; 212 Word __fastcall WeekOfTheYear(const TDateTime AValue, Word &AYear)/* overload */; 213 Word __fastcall DayOfTheYear(const TDateTime AValue); 214 Word __fastcall HourOfTheYear(const TDateTime AValue); 215 unsigned __fastcall MinuteOfTheYear(const TDateTime AValue); 216 unsigned __fastcall SecondOfTheYear(const TDateTime AValue); 217 __int64 __fastcall MilliSecondOfTheYear(const TDateTime AValue); 218 Word __fastcall WeekOfTheMonth(const TDateTime AValue)/* overload */; 219 Word __fastcall WeekOfTheMonth(const TDateTime AValue, Word &AYear, Word &AMonth)/* overload */; 220 Word __fastcall DayOfTheMonth(const TDateTime AValue); 221 Word __fastcall HourOfTheMonth(const TDateTime AValue); 222 Word __fastcall MinuteOfTheMonth(const TDateTime AValue); 223 unsigned __fastcall SecondOfTheMonth(const TDateTime AValue); 224 unsigned __fastcall MilliSecondOfTheMonth(const TDateTime AValue); 225 Word __fastcall DayOfTheWeek(const TDateTime AValue); 226 Word __fastcall HourOfTheWeek(const TDateTime AValue); 227 Word __fastcall MinuteOfTheWeek(const TDateTime AValue); 228 unsigned __fastcall SecondOfTheWeek(const TDateTime AValue); 229 unsigned __fastcall MilliSecondOfTheWeek(const TDateTime AValue); 230 Word __fastcall HourOfTheDay(const TDateTime AValue); 231 Word __fastcall MinuteOfTheDay(const TDateTime AValue); 232 unsigned __fastcall SecondOfTheDay(const TDateTime AValue); 233 unsigned __fastcall MilliSecondOfTheDay(const TDateTime AValue); 234 Word __fastcall MinuteOfTheHour(const TDateTime AValue); 235 Word __fastcall SecondOfTheHour(const TDateTime AValue); 236 unsigned __fastcall MilliSecondOfTheHour(const TDateTime AValue); 237 Word __fastcall SecondOfTheMinute(const TDateTime AValue); 238 unsigned __fastcall MilliSecondOfTheMinute(const TDateTime AValue); 239 Word __fastcall MilliSecondOfTheSecond(const TDateTime AValue); 240 bool __fastcall WithinPastYears(const TDateTime ANow, const TDateTime AThen, const int AYears); 241 bool __fastcall WithinPastMonths(const TDateTime ANow, const TDateTime AThen, const int AMonths); 242 bool __fastcall WithinPastWeeks(const TDateTime ANow, const TDateTime AThen, const int AWeeks); 243 bool __fastcall WithinPastDays(const TDateTime ANow, const TDateTime AThen, const int ADays); 244 bool __fastcall WithinPastHours(const TDateTime ANow, const TDateTime AThen, const __int64 AHours); 245 bool __fastcall WithinPastMinutes(const TDateTime ANow, const TDateTime AThen, const __int64 AMinutes); 246 bool __fastcall WithinPastSeconds(const TDateTime ANow, const TDateTime AThen, const __int64 ASeconds); 247 bool __fastcall WithinPastMilliSeconds(const TDateTime ANow, const TDateTime AThen, const __int64 AMilliSeconds);
Between 248 int __fastcall YearsBetween(const TDateTime ANow, const TDateTime AThen); 249 int __fastcall MonthsBetween(const TDateTime ANow, const TDateTime AThen); 250 int __fastcall WeeksBetween(const TDateTime ANow, const TDateTime AThen); 251 int __fastcall DaysBetween(const TDateTime ANow, const TDateTime AThen); 252 __int64 __fastcall HoursBetween(const TDateTime ANow, const TDateTime AThen); 253 __int64 __fastcall MinutesBetween(const TDateTime ANow, const TDateTime AThen); 254 __int64 __fastcall SecondsBetween(const TDateTime ANow, const TDateTime AThen); 255 __int64 __fastcall MilliSecondsBetween(const TDateTime ANow, const TDateTime AThen); 256 bool __fastcall DateTimeInRange(TDateTime ADateTime, TDateTime AStartDateTime, TDateTime AEndDateTime, bool aInclusive = true); 257 bool __fastcall TimeInRange(TTime ATime, TTime AStartTime, TTime AEndTime, bool AInclusive = true); 258 bool __fastcall DateInRange(TDate ADate, TDate AStartDate, TDate AEndDate, bool AInclusive = true); 259 double __fastcall YearSpan(const TDateTime ANow, const TDateTime AThen); 260 double __fastcall MonthSpan(const TDateTime ANow, const TDateTime AThen); 261 double __fastcall WeekSpan(const TDateTime ANow, const TDateTime AThen); 262 double __fastcall DaySpan(const TDateTime ANow, const TDateTime AThen); 263 double __fastcall HourSpan(const TDateTime ANow, const TDateTime AThen); 264 double __fastcall MinuteSpan(const TDateTime ANow, const TDateTime AThen); 265 double __fastcall SecondSpan(const TDateTime ANow, const TDateTime AThen); 266 double __fastcall MilliSecondSpan(const TDateTime ANow, const TDateTime AThen); 267 TDateTime __fastcall IncYear(const TDateTime AValue, const int ANumberOfYears = 0x1); 268 TDateTime __fastcall IncWeek(const TDateTime AValue, const int ANumberOfWeeks = 0x1); 269 TDateTime __fastcall IncDay(const TDateTime AValue, const int ANumberOfDays = 0x1); 270 #ifndef _WIN64 271 TDateTime __fastcall IncHour(const TDateTime AValue, const __int64 ANumberOfHours = 1LL); 272 TDateTime __fastcall IncMinute(const TDateTime AValue, const __int64 ANumberOfMinutes = 1LL); 273 TDateTime __fastcall IncSecond(const TDateTime AValue, const __int64 ANumberOfSeconds = 1LL); 274 TDateTime __fastcall IncMilliSecond(const TDateTime AValue, const __int64 ANumberOfMilliSeconds = 1LL); 275 #else /* _WIN64 */ 276 TDateTime __fastcall IncHour(const TDateTime AValue, const __int64 ANumberOfHours = (__int64)(1LL)); 277 TDateTime __fastcall IncMinute(const TDateTime AValue, const __int64 ANumberOfMinutes = (__int64)(1LL)); 278 TDateTime __fastcall IncSecond(const TDateTime AValue, const __int64 ANumberOfSeconds = (__int64)(1LL)); 279 TDateTime __fastcall IncMilliSecond(const TDateTime AValue, const __int64 ANumberOfMilliSeconds = (__int64)(1LL)); 280 #endif /* _WIN64 */ 281 TDateTime __fastcall EncodeDateTime(const Word AYear, const Word AMonth, const Word ADay, const Word AHour, const Word AMinute, const Word ASecond, const Word AMilliSecond); 282 void __fastcall DecodeDateTime(const TDateTime AValue, /* out */ Word &AYear, /* out */ Word &AMonth, /* out */ Word &ADay, /* out */ Word &AHour, /* out */ Word &AMinute, /* out */ Word &ASecond, /* out */ Word &AMilliSecond); 283 TDateTime __fastcall EncodeDateWeek(const Word AYear, const Word AWeekOfYear, const Word ADayOfWeek = (Word)(0x1)); 284 void __fastcall DecodeDateWeek(const TDateTime AValue, /* out */ Word &AYear, /* out */ Word &AWeekOfYear, /* out */ Word &ADayOfWeek); 285 TDateTime __fastcall EncodeDateDay(const Word AYear, const Word ADayOfYear); 286 void __fastcall DecodeDateDay(const TDateTime AValue, /* out */ Word &AYear, /* out */ Word &ADayOfYear); 287 TDateTime __fastcall EncodeDateMonthWeek(const Word AYear, const Word AMonth, const Word AWeekOfMonth, const Word ADayOfWeek); 288 void __fastcall DecodeDateMonthWeek(const TDateTime AValue, /* out */ Word &AYear, /* out */ Word &AMonth, /* out */ Word &AWeekOfMonth, /* out */ Word &ADayOfWeek); 289 bool __fastcall TryEncodeDateTime(const Word AYear, const Word AMonth, const Word ADay, const Word AHour, const Word AMinute, const Word ASecond, const Word AMilliSecond, /* out */ TDateTime &AValue); 290 bool __fastcall TryEncodeDateWeek(const Word AYear, const Word AWeekOfYear, /* out */ TDateTime &AValue, const Word ADayOfWeek = (Word)(0x1)); 291 bool __fastcall TryEncodeDateDay(const Word AYear, const Word ADayOfYear, /* out */ TDateTime &AValue); 292 bool __fastcall TryEncodeDateMonthWeek(const Word AYear, const Word AMonth, const Word AWeekOfMonth, const Word ADayOfWeek, TDateTime &AValue); 293 TDateTime __fastcall RecodeYear(const TDateTime AValue, const Word AYear); 294 TDateTime __fastcall RecodeMonth(const TDateTime AValue, const Word AMonth); 295 TDateTime __fastcall RecodeDay(const TDateTime AValue, const Word ADay); 296 TDateTime __fastcall RecodeHour(const TDateTime AValue, const Word AHour); 297 TDateTime __fastcall RecodeMinute(const TDateTime AValue, const Word AMinute); 298 TDateTime __fastcall RecodeSecond(const TDateTime AValue, const Word ASecond); 299 TDateTime __fastcall RecodeMilliSecond(const TDateTime AValue, const Word AMilliSecond); 300 TDateTime __fastcall RecodeDate(const TDateTime AValue, const Word AYear, const Word AMonth, const Word ADay); 301 TDateTime __fastcall RecodeTime(const TDateTime AValue, const Word AHour, const Word AMinute, const Word ASecond, const Word AMilliSecond); 302 TDateTime __fastcall RecodeDateTime(const TDateTime AValue, const Word AYear, const Word AMonth, const Word ADay, const Word AHour, const Word AMinute, const Word ASecond, const Word AMilliSecond); 303 bool __fastcall TryRecodeDateTime(const TDateTime AValue, const Word AYear, const Word AMonth, const Word ADay, const Word AHour, const Word AMinute, const Word ASecond, const Word AMilliSecond, /* out */ TDateTime &AResult); 304 Types::TValueRelationship __fastcall CompareDateTime(const TDateTime A, const TDateTime B); 305 bool __fastcall SameDateTime(const TDateTime A, const TDateTime B); 306 Types::TValueRelationship __fastcall CompareDate(const TDateTime A, const TDateTime B); 307 bool __fastcall SameDate(const TDateTime A, const TDateTime B); 308 Types::TValueRelationship __fastcall CompareTime(const TDateTime A, const TDateTime B); 309 bool __fastcall SameTime(const TDateTime A, const TDateTime B); 310 Word __fastcall NthDayOfWeek(const TDateTime AValue); 311 void __fastcall DecodeDayOfWeekInMonth(const TDateTime AValue, /* out */ Word &AYear, /* out */ Word &AMonth, /* out */ Word &ANthDayOfWeek, /* out */ Word &ADayOfWeek); 312 TDateTime __fastcall EncodeDayOfWeekInMonth(const Word AYear, const Word AMonth, const Word ANthDayOfWeek, const Word ADayOfWeek); 313 bool __fastcall TryEncodeDayOfWeekInMonth(const Word AYear, const Word AMonth, const Word ANthDayOfWeek, const Word ADayOfWeek, /* out */ TDateTime &AValue); 314 double __fastcall DateTimeToJulianDate(const TDateTime AValue); 315 TDateTime __fastcall JulianDateToDateTime(const double AValue); 316 bool __fastcall TryJulianDateToDateTime(const double AValue, /* out */ TDateTime &ADateTime); 317 double __fastcall DateTimeToModifiedJulianDate(const TDateTime AValue); 318 TDateTime __fastcall ModifiedJulianDateToDateTime(const double AValue); 319 bool __fastcall TryModifiedJulianDateToDateTime(const double AValue, /* out */ TDateTime &ADateTime); 320 __int64 __fastcall DateTimeToUnix(const TDateTime AValue, bool AInputIsUTC = true); 321 TDateTime __fastcall UnixToDateTime(const __int64 AValue, bool AReturnUTC = true); 322 void __fastcall InvalidDateTimeError(const Word AYear, const Word AMonth, const Word ADay, const Word AHour, const Word AMinute, const Word ASecond, const Word AMilliSecond, const TDateTime ABaseDate = 0.000000E+00); 323 void __fastcall InvalidDateWeekError(const Word AYear, const Word AWeekOfYear, const Word ADayOfWeek); 324 void __fastcall InvalidDateDayError(const Word AYear, const Word ADayOfYear); 325 void __fastcall InvalidDateMonthWeekError(const Word AYear, const Word AMonth, const Word AWeekOfMonth, const Word ADayOfWeek); 326 void __fastcall InvalidDayOfWeekInMonthError(const Word AYear, const Word AMonth, const Word ANthDayOfWeek, const Word ADayOfWeek); 327 UnicodeString __fastcall DateToISO8601(const TDateTime ADate, bool AInputIsUTC = true); 328 TDateTime __fastcall ISO8601ToDate(const UnicodeString AISODate, bool AReturnUTC = true); 329 bool __fastcall TryISO8601ToDate(const UnicodeString AISODate, /* out */ TDateTime &Value, bool AReturnUTC = true); 330 } /* namespace Dateutils */ 331 } /* namespace System */