绿茵场的激情

unit DateUtils;interfaceuses SysUtils, Math, Types;// 把完整时间分解成日期和时间两部分function DateOf(const AValue: TDateTime): TDateTime;function TimeOf(const AValue: TDateTime): TDateTime;// 判断是否有效时间 function IsInLeapYear(const AValue: TDateTime): Boolean;function IsPM(const AValue: TDateTime): Boolean;function IsValidDate(const AYear, AMonth, ADay: Word): Boolean;function IsValidTime(const AHour, AMinute, ASecond, AMilliSecond: Word): Boolean;function IsValidDateTime(const AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond: Word): Boolean;function IsValidDateDay(const AYear, ADayOfYear: Word): Boolean;function IsValidDateWeek(const AYear, AWeekOfYear, ADayOfWeek: Word): Boolean;function IsValidDateMonthWeek(const AYear, AMonth, AWeekOfMonth, ADayOfWeek: Word): Boolean;// 年月包含的天数和星期数WeeksInAYear(DaysInYear(const AValue: TDateTime): Word;function DaysInAYear(const AYear: Word): Word;function DaysInMonth(const AValue: TDateTime): Word;function DaysInAMonth(const AYear, AMonth: Word): Word;function Today: TDateTime;function Yesterday: TDateTime;function Tomorrow: TDateTime;function IsToday(const AValue: TDateTime): Boolean;function IsSameDay(const AValue, ABasis: TDateTime): Boolean;// 得到当前时间的年、第几个月、第几个星期、天function YearOf(const AValue: TDateTime): Word;function MonthOf(const AValue: TDateTime): Word;function WeekOf(const AValue: TDateTime): Word; {WeekOf函数会得到该星期为一年的第几个星期}function DayOf(const AValue: TDateTime): Word;function HourOf(const AValue: TDateTime): Word;function MinuteOf(const AValue: TDateTime): Word;function SecondOf(const AValue: TDateTime): Word;function MilliSecondOf(const AValue: TDateTime): Word;// 年月日星期的起止时间function StartOfTheYear(const AValue: TDateTime): TDateTime;function EndOfTheYear(const AValue: TDateTime): TDateTime;function StartOfAYear(const AYear: Word): TDateTime;function EndOfAYear(const AYear: Word): TDateTime;function StartOfTheMonth(const AValue: TDateTime): TDateTime;function EndOfTheMonth(const AValue: TDateTime): TDateTime;function StartOfAMonth(const AYear, AMonth: Word): TDateTime;function EndOfAMonth(const AYear, AMonth: Word): TDateTime;EndOfTheWeek(StartOfAWeek(const AYear, AWeekOfYear: Word; const ADayOfWeek: Word = 1): TDateTime;function EndOfAWeek(const AYear, AWeekOfYear: Word; const ADayOfWeek: Word = 7): TDateTime;function StartOfTheDay(const AValue: TDateTime): TDateTime;function EndOfTheDay(const AValue: TDateTime): TDateTime;function StartOfADay(const AYear, AMonth, ADay: Word): TDateTime; overload;function EndOfADay(const AYear, AMonth, ADay: Word): TDateTime; overload;function StartOfADay(const AYear, ADayOfYear: Word): TDateTime; overload;function EndOfADay(const AYear, ADayOfYear: Word): TDateTime; overload;MonthOfTheYear(const AValue: TDateTime): Word;WeekOfTheYear(const AValue: TDateTime; var AYear: Word): Word; overload;function DayOfTheYear(const AValue: TDateTime): Word;function HourOfTheYear(const AValue: TDateTime): Word;function MinuteOfTheYear(const AValue: TDateTime): LongWord;function SecondOfTheYear(const AValue: TDateTime): LongWord;function MilliSecondOfTheYear(const AValue: TDateTime): Int64;WeekOfTheMonth(const AValue: TDateTime; var AYear, AMonth: Word): Word; overload;function DayOfTheMonth(const AValue: TDateTime): Word; // 一个月的第几天function HourOfTheMonth(const AValue: TDateTime): Word;function MinuteOfTheMonth(const AValue: TDateTime): Word;function SecondOfTheMonth(const AValue: TDateTime): LongWord;function MilliSecondOfTheMonth(const AValue: TDateTime): LongWord;// 返回星期几,1表示星期一,而7表示星期日。 星期一是一周的第一天,ISO 8601function DayOfTheWeek(HourOfTheWeek(MinuteOfTheWeek(SecondOfTheWeek(MilliSecondOfTheWeek(HourOfTheDay(const AValue: TDateTime): Word;function MinuteOfTheDay(const AValue: TDateTime): Word;function SecondOfTheDay(const AValue: TDateTime): LongWord;function MilliSecondOfTheDay(const AValue: TDateTime): LongWord;function MinuteOfTheHour(const AValue: TDateTime): Word;function SecondOfTheHour(const AValue: TDateTime): Word;function MilliSecondOfTheHour(const AValue: TDateTime): LongWord;function SecondOfTheMinute(const AValue: TDateTime): Word;function MilliSecondOfTheMinute(const AValue: TDateTime): LongWord;function MilliSecondOfTheSecond(const AValue: TDateTime): Word;{ For a given date these functions tell you the which day of the week of the month (or year). If its a Thursday, they will tell you if its the first, second, etc Thursday of the month (or year). Remember, even though its the first Thursday of the year it doesn’t mean its the first week of the year. See ISO 8601 above for more information. }function NthDayOfWeek(const AValue: TDateTime): Word;WithinPastYears(const ANow, AThen: TDateTime; const AYears: Integer): Boolean;function WithinPastMonths(const ANow, AThen: TDateTime; const AMonths: Integer): Boolean;function WithinPastWeeks(const ANow, AThen: TDateTime; const AWeeks: Integer): Boolean;function WithinPastDays(const ANow, AThen: TDateTime; const ADays: Integer): Boolean;function WithinPastHours(const ANow, AThen: TDateTime; const AHours: Int64): Boolean;function WithinPastMinutes(const ANow, AThen: TDateTime; const AMinutes: Int64): Boolean;function WithinPastSeconds(const ANow, AThen: TDateTime; const ASeconds: Int64): Boolean;function WithinPastMilliSeconds(const ANow, AThen: TDateTime; const AMilliSeconds: Int64): Boolean;YearsBetween(const ANow, AThen: TDateTime): Integer;function MonthsBetween(const ANow, AThen: TDateTime): Integer;function WeeksBetween(const ANow, AThen: TDateTime): Integer;function DaysBetween(const ANow, AThen: TDateTime): Integer;function HoursBetween(const ANow, AThen: TDateTime): Int64;function MinutesBetween(const ANow, AThen: TDateTime): Int64;function SecondsBetween(const ANow, AThen: TDateTime): Int64;function MilliSecondsBetween(const ANow, AThen: TDateTime): Int64;YearSpan(const ANow, AThen: TDateTime): Double;function MonthSpan(const ANow, AThen: TDateTime): Double;function WeekSpan(const ANow, AThen: TDateTime): Double;function DaySpan(const ANow, AThen: TDateTime): Double;function HourSpan(const ANow, AThen: TDateTime): Double;function MinuteSpan(const ANow, AThen: TDateTime): Double;function SecondSpan(const ANow, AThen: TDateTime): Double;function MilliSecondSpan(const ANow, AThen: TDateTime): Double;IncYear(const AValue: TDateTime; const ANumberOfYears: Integer = 1): TDateTime;// function IncMonth is in SysUtilsfunction IncWeek(const AValue: TDateTime; const ANumberOfWeeks: Integer = 1): TDateTime;function IncDay(const AValue: TDateTime; const ANumberOfDays: Integer = 1): TDateTime;function IncHour(const AValue: TDateTime; const ANumberOfHours: Int64 = 1): TDateTime;function IncMinute(const AValue: TDateTime; const ANumberOfMinutes: Int64 = 1): TDateTime;function IncSecond(const AValue: TDateTime; const ANumberOfSeconds: Int64 = 1): TDateTime;function IncMilliSecond(const AValue: TDateTime; const ANumberOfMilliSeconds: Int64 = 1): TDateTime;EncodeDateTime(const AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond: Word): TDateTime;procedure DecodeDateTime(const AValue: TDateTime; out AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond: Word);function EncodeDateWeek(const AYear, AWeekOfYear: Word; const ADayOfWeek: Word = 1): TDateTime;procedure DecodeDateWeek(const AValue: TDateTime; out AYear, AWeekOfYear, ADayOfWeek: Word);function EncodeDateDay(const AYear, ADayOfYear: Word): TDateTime;procedure DecodeDateDay(const AValue: TDateTime; out AYear, ADayOfYear: Word);function EncodeDateMonthWeek(const AYear, AMonth, AWeekOfMonth, ADayOfWeek: Word): TDateTime;procedure DecodeDateMonthWeek(const AValue: TDateTime; out AYear, AMonth, AWeekOfMonth, ADayOfWeek: Word);function TryEncodeDateTime(const AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond: Word; out AValue: TDateTime): Boolean;function TryEncodeDateWeek(const AYear, AWeekOfYear: Word; out AValue: TDateTime; const ADayOfWeek: Word = 1): Boolean;function TryEncodeDateDay(const AYear, ADayOfYear: Word; out AValue: TDateTime): Boolean;function TryEncodeDateMonthWeek(const AYear, AMonth, AWeekOfMonth, ADayOfWeek: Word; var AValue: TDateTime): Boolean;function TryRecodeDateTime(const AValue: TDateTime; const AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond: Word; out AResult: TDateTime): Boolean;procedure DecodeDayOfWeekInMonth(const AValue: TDateTime; out AYear, AMonth, ANthDayOfWeek, ADayOfWeek: Word);function EncodeDayOfWeekInMonth(const AYear, AMonth, ANthDayOfWeek, ADayOfWeek: Word): TDateTime;function TryEncodeDayOfWeekInMonth(const AYear, AMonth, ANthDayOfWeek, ADayOfWeek: Word; out AValue: TDateTime): Boolean;RecodeYear(const AValue: TDateTime; const AYear: Word): TDateTime;function RecodeMonth(const AValue: TDateTime; const AMonth: Word): TDateTime;function RecodeDay(const AValue: TDateTime; const ADay: Word): TDateTime;function RecodeHour(const AValue: TDateTime; const AHour: Word): TDateTime;function RecodeMinute(const AValue: TDateTime; const AMinute: Word): TDateTime;function RecodeSecond(const AValue: TDateTime; const ASecond: Word): TDateTime;function RecodeMilliSecond(const AValue: TDateTime; const AMilliSecond: Word): TDateTime;function RecodeDate(const AValue: TDateTime; const AYear, AMonth, ADay: Word): TDateTime;function RecodeTime(const AValue: TDateTime; const AHour, AMinute, ASecond, AMilliSecond: Word): TDateTime;function RecodeDateTime(const AValue: TDateTime; const AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond: Word): TDateTime;CompareDateTime(const A, B: TDateTime): TValueRelationship;function SameDateTime(const A, B: TDateTime): Boolean;function CompareDate(const A, B: TDateTime): TValueRelationship;function SameDate(const A, B: TDateTime): Boolean;function CompareTime(const A, B: TDateTime): TValueRelationship;function SameTime(const A, B: TDateTime): Boolean;InvalidDateTimeError(const AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond: Word; const ABaseDate: TDateTime = 0);procedure InvalidDateWeekError(const AYear, AWeekOfYear, ADayOfWeek: Word);procedure InvalidDateDayError(const AYear, ADayOfYear: Word);procedure InvalidDateMonthWeekError(const AYear, AMonth, AWeekOfMonth, ADayOfWeek: Word);procedure InvalidDayOfWeekInMonthError(const AYear, AMonth, ANthDayOfWeek, ADayOfWeek: Word);DateTimeToJulianDate(const AValue: TDateTime): Double;function JulianDateToDateTime(const AValue: Double): TDateTime;function TryJulianDateToDateTime(const AValue: Double; out ADateTime: TDateTime): Boolean;function DateTimeToModifiedJulianDate(const AValue: TDateTime): Double;function ModifiedJulianDateToDateTime(const AValue: Double): TDateTime;function TryModifiedJulianDateToDateTime(const AValue: Double; out ADateTime: TDateTime): Boolean;DateTimeToUnix(const AValue: TDateTime): Int64;function UnixToDateTime(const AValue: Int64): TDateTime;DaysPerWeek = 7; WeeksPerFortnight = 2; MonthsPerYear = 12; YearsPerDecade = 10; YearsPerCentury = 100; YearsPerMillennium = 1000;DayMonday = 1; DayTuesday = 2; DayWednesday = 3; DayThursday = 4; DayFriday = 5; DaySaturday = 6; DaySunday = 7;OneHour = 1 / HoursPerDay; OneMinute = 1 / MinsPerDay; OneSecond = 1 / SecsPerDay; OneMillisecond = 1 / MSecsPerDay;DaysPerYear: array [Boolean] of Word = (365, 366);ApproxDaysPerMonth: Double = 30.4375; ApproxDaysPerYear: Double = 365.25;implementationuses RTLConsts;function DateOf(const AValue: TDateTime): TDateTime;begin Result := Trunc(AValue);end;function TimeOf(const AValue: TDateTime): TDateTime;begin Result := Frac(AValue);end;const CDayMap: array [1..7] of Word = (7, 1, 2, 3, 4, 5, 6);CompareDate 比较两个日期时间值日期部分的大小当你开展的事业从事的行动穷途末路大势已去的时候,

绿茵场的激情

相关文章:

你感兴趣的文章:

标签云: