DateUtils所有時間函數


unit DateUtils;

interface

uses
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;

// 年月包含的天數和星期數
function WeeksInYear(const AValue: TDateTime): Word; {ISO 8601}
function WeeksInAYear(const AYear: Word): Word; {ISO 8601}
function 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;

function StartOfTheWeek(const AValue: TDateTime): TDateTime; {ISO 8601}
function EndOfTheWeek(const AValue: TDateTime): TDateTime; {ISO 8601}
function 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;

{ 時間順序函數 }
function MonthOfTheYear(const AValue: TDateTime): Word;
function WeekOfTheYear(const AValue: TDateTime): Word; overload; {ISO 8601}
function 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;

function WeekOfTheMonth(const AValue: TDateTime): Word; overload; {ISO 8601x}
function 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 8601 
function
DayOfTheWeek(const AValue: TDateTime): Word; {ISO 8601}
function HourOfTheWeek(const AValue: TDateTime): Word; {ISO 8601}
function MinuteOfTheWeek(const AValue: TDateTime): Word; {ISO 8601}
function SecondOfTheWeek(const AValue: TDateTime): LongWord; {ISO 8601}
function MilliSecondOfTheWeek(const AValue: TDateTime): LongWord; {ISO 8601}

function 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;


{ 范圍檢查函數 }
function 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;

{ Range query functions }
{ 范圍查詢函數 }
function 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;

{ Range spanning functions }
{ 范圍跨度函數 }
function 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;

{ Increment/decrement datetime fields }
{ 時間增減函數}
function IncYear(const AValue: TDateTime; const ANumberOfYears: Integer = 1): TDateTime;
// function IncMonth is in SysUtils
function 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;

{ 時間組成函數}
function 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;

{ Recode functions for datetime fields }
{ 重編碼時間函數}
function 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;

{ Fuzzy comparison }
{ 不准確的比較}
function 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;

{ 錯誤報告 }
procedure 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);

{ Julian and Modified Julian Date conversion support }
{ Be aware that not all Julian Dates (or MJD) are encodable as a TDateTime }
function 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;

{ Unix 轉換 }
function DateTimeToUnix(const AValue: TDateTime): Int64;
function UnixToDateTime(const AValue: Int64): TDateTime;

{ Constants used in this unit }

const
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);

var

{ average over a 4 year span }
ApproxDaysPerMonth: Double = 30.4375;
ApproxDaysPerYear: Double = 365.25;

implementation

uses
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 比較兩個日期時間值日期部分的大小
CompareDateTime 比較兩個日期時間值的大小
CompareTime 比較兩個日期時間值時間部分的大小
DateOf 去除日期時間值的時間部分
DateTimeToJulianDate 轉換日期時間值為儒略日
DateTimeToModifiedJulianDate 轉換日期時間值為改進的儒略日
DateTimeToUnix 轉換日期時間值為Unix/Linus日期時間值
Day of week 常量 ISO 8601標准中一周各天順序的 常量
DayOf 返回一個日期時間值的天
DayOfTheMonth 返回一個日期時間值的天
DayOfTheWeek 返回一個日期時間值是那星期的第幾天
DayOfTheYear 返回一個日期時間值是那年的第多少天
DaysBetween 返回兩個日期時間值之間相差的整數天數
DaysInAMonth 返回指定年、月的天數
DaysInAYear 返回指定年的天數
DaysInMonth 返回一個日期時間值的那個月的天數
DaysInYear 返回一個日期時間值的那一年的天數
DaySpan 返回兩個日期時間值之間相差的小數天數
DecodeDateDay 返回一個日期時間值的年份和是一年的第多少天
DecodeDateMonthWeek 返回一個日期時間值的年、月、那個月的第幾周、那周的第幾天
DecodeDateTime 返回一個日期時間值的年、月、日、時、分、秒、毫秒
DecodeDateWeek 返回一個日期時間值的年、一年的第多少周、一周的第幾天
DecodeDayOfWeekInMonth 返回一個日期時間值的年、月、一周的第幾天、那個月的第幾個星期幾
EncodeDateDay 返回指定年和一年的第多少天的日期時間值
EncodeDateMonthWeek 返回指定年、月、那個月的第幾周、那周的第幾天的日期時間值
EncodeDateTime 返回指定年、月、日、時、分、秒,毫秒返的日期時間值
EncodeDateWeek 返回指定年、那年的第多少周、那周的第幾天的日期時間值
EncodeDayOfWeekInMonth 返回指定年、月、那個月的第幾個星期幾的日期時間值
EndOfADay 返回指定年、那年第多少天的最后一秒的日期時間值
EndOfAMonth 返回指定年、月的最后一天最后一秒的日期時間值
EndOfAWeek 返回指定年、那年第多少周、那周第幾天的最后一秒的日期時間值
EndOfAYear 返回指定年的最后一天最后一秒的日期時間值
EndOfTheDay 返回指定日期時間值的那一天最后一秒的日期時間值
EndOfTheMonth 返回指定日期時間值的那個月的最后一天最后一秒的日期時間值
EndOfTheWeek 返回指定日期時間值的那一周的最后一天最后一秒的日期時間值
EndOfTheYear 返回指定日期時間值的那一年最后一天最后一秒的日期時間值
HourOf   返回指定日期時間值的小時部分
HourOfTheDay   返回指定日期時間值的小時部分.
HourOfTheMonth   返回從指定日期時間值的那個月的第一天0點到指定日期的小時已經度過的小時數
HourOfTheWeek   返回從指定日期時間值中那一周第一天0點到指定日期的那個小時 已經度過的小時數
HourOfTheYear   返回從指定日期時間值中 那一年第一天0點到指定日期的那個小時已經度過的小時數
HoursBetween   返回兩個指定日期時間值之間相差的小時數
HourSpan   返回兩個指定日期時間值之間相差的小時數(包括小數部分)
IncDay   返回日期時間值向后推移指定天數后的值
IncHour   返回日期時間值向后推移指定小時數的值
IncMilliSecond   返回日期時間值向后推移指定毫秒數的值
IncMinute   返回日期時間值向后推移指定分鍾數的值
IncSecond   返回日期時間值向后推移指定秒數的值
IncWeek   返回日期時間值向后推移指定星期數的值
IncYear   返回日期時間值向后推移指定星期數的值
IsInLeapYear   判斷指定的日期時間值的年份是否為閏年
IsPM   判斷指定的日期時間值的時間是否是中午12:0:0之后
IsSameDay   判斷一個日期時間值與標准日期時間值是否是同一天
IsToday   判斷一個日期時間值是否是當天
IsValidDate   判斷指定的年、月、日是否是有效的日期
IsValidDateDay   判斷指定的年、該年的天數是否是該年有效的天數
IsValidDateMonthWeek   判斷指定的年、月、該月的第幾周、該周的第幾天是否是有效的日期
IsValidDateTime   判斷指定的年、月、日、時、分、秒、毫秒是否是有效的日期時間值
IsValidDateWeek   判斷指定的年、該年的第多少周、該周第幾天是否是有效的日期
IsValidTime   判斷指定的時、分、秒、毫秒是否是有效的時間
JulianDateToDateTime   轉換儒略日期為日期時間值
MilliSecondOf   返回指定日期時間值的毫秒部分
MilliSecondOfTheDay   返回指定日期時間值的那天0時0分0秒0毫秒開始到其指定時間的毫秒數
MilliSecondOfTheHour   返回指定日期時間值的那一小時0分0秒0毫秒開始到其指定時間的毫秒數
MilliSecondOfTheMinute   返回指定日期時間值的那一分鍾0秒0毫秒開始到其指定時間的毫秒數
MilliSecondOfTheMonth   返回指定日期時間值的那個月1日分鍾0秒0毫秒開始到其指定時間的毫秒數
MilliSecondOfTheSecond   返回指定日期時間值的毫秒部分
MilliSecondOfTheWeek   返回指定日期時間值的那周星期一0時0分0秒0毫秒到其指定時間的毫秒數
MilliSecondOfTheYear   返回指定日期時間值的那年1月1日0時0分0秒0毫秒到其指定時間的毫秒數
MilliSecondsBetween   返回兩個指定日期時間值之間相差的毫秒數(整數)
MilliSecondSpan   返回兩個指定日期時間值 之間相差的毫秒數(小數)
MinuteOf   返回指定日期時間值 分鍾部分
MinuteOfTheDay   返回指定日期時間值的那天0時0分開始到其指定時間的分鍾數
MinuteOfTheHour   返回指定日期時間值的分鍾部分
MinuteOfTheMonth   返回指定日期時間值的那個月1日0時0分開始到其指定時間的分鍾數
MinuteOfTheWeek   返回指定日期時間值的那周第1天0時0分開始到其指定時間的分鍾數
MinuteOfTheYear   返回指定日期時間值的那年1月1日0時0分開始到其指定時間的分鍾數
MinutesBetween   返回兩個指定日期時間值之間相差的分鍾數(整數)
MinuteSpan   返回兩個指定日期時間值之間相差的分鍾數(包含小數)
ModifiedJulianDateToDateTime   轉換修正的儒略日為日期時間值
MonthOf   返回指定日期時間值的月份部分
MonthOfTheYear   返回指定日期時間值的月份部分
MonthsBetween   返回兩個指定日期時間值之間相差的月份(整數)
MonthSpan   返回兩個指定日期時間值之間相差的月份(包含小數)
NthDayOfWeek   返回指定日期時間值該月的第幾個星期幾
OneHour 常量 Delphi與時間成反比的常量
OneMillisecond 常量 Delphi與時間成反比的常量
OneMinute 常量 Delphi與時間成反比的常量
OneSecond 常量 Delphi與時間成反比的常量
RecodeDate   替換指定日期時間值的日期部分
RecodeDateTime   選擇替換指定日期時間值
RecodeDay   替換指定日期時間值 的日部分
RecodeHour   替換指定日期時間值 的小時部分
RecodeMilliSecond   替換指定日期時間值的毫秒部分
RecodeMinute   替換指定日期時間值的分鍾部分
RecodeMonth   替換指定日期時間值的月份部分
RecodeSecond   替換指定日期時間值的秒部分
RecodeTime   替換指定日期時間值的時間部分
RecodeYear   替換指定日期時間值的年份部分
SameDate   判斷兩個日期時間值的年、月、日部分是否相同
SameDateTime   判斷兩個日期時間值的年、月、日、時、分、秒、毫秒是否相同
SameTime   判斷兩個日期時間值的時、分、秒、毫秒部分是否相同
SecondOf   返回指定日期時間值的秒部分
SecondOfTheDay   返回從指定日期時間值那天0時0分0秒到其指定時間的秒數
SecondOfTheHour   返回從指定日期時間值那小時0分0秒到其指定時間的秒數
SecondOfTheMinute   返回從指定日期時間值那分鍾0秒到其指定時間的秒數
SecondOfTheMonth   返回從指定日期時間值那個月1日0時0分0秒到其指定時間的秒數
SecondOfTheWeek   返回從指定日期時間值所在周的星期一0時0分0秒到其指定時間的秒數
SecondOfTheYear   返回從指定日期時間值那年的1月1日0時0分0秒到其指定時間的秒數
SecondsBetween   返回兩個指定日期時間值之間相差的秒數(整數)
SecondSpan   返回兩個指定日期時間值之間相差的秒數(包含小數)
StartOfADay   返回指定那天開始(0時0分0秒0毫秒)的日期時間值
StartOfAMonth   返回指定年、月的第一天開始(0時0分0秒0毫秒)的日期時間值
StartOfAWeek   返回指定年、第多少周、第幾天開始(0時0分0秒0毫秒)的日期時間值
StartOfAYear   返回指定年開始(1月1日0時0分0秒0毫秒)的日期時間值
StartOfTheDay   返回指定日期時間值那天開始(0時0分0秒0毫秒)的日期時間值
StartOfTheMonth   返回指定日期時間值那個月開始(1日0時0分0秒0毫秒)的日期時間值
StartOfTheWeek   返回指定日期時間值那周開始(第一天0時0分0秒0毫秒)的日期時間值
StartOfTheYear   返回指定日期時間值那年開始(1月1日0時0分0秒0毫秒)的日期時間值
TimeOf   返回指定日期時間值的時間部分
Today   返回當天的日期
Tomorrow   返回下一天的日期
TryEncodeDateDay   計算指定年、該年第多少天的日期時間值
TryEncodeDateMonthWeek   計算指定年、月、該月第幾周、該周第幾天的日期時間值
TryEncodeDateTime   轉換指定年、月、日、時、分、秒、毫秒為日期時間值
TryEncodeDateWeek   轉換指定年、該第多少周、該周第幾天為日期時間值
TryEncodeDayOfWeekInMonth   轉換指定年、月、該月第幾個星期幾為日期時間值
TryJulianDateToDateTime   轉換指定儒略日為日期時間值
TryModifiedJulianDateToDateTime   轉換指定修正儒略日為日期時間值
TryRecodeDateTime   選擇替換指定日期時間值的某些部分
UnixToDateTime   轉換Unix或Linux日期、時間值為Delphi日期時間值
WeekOf   返回指定日期時間值是某年的第多少周
WeekOfTheMonth   返回指定日期時間值是某月的第 幾周
WeekOfTheYear   返回指定日期時間值是某年的第多少周
WeeksBetween   返回兩個指定日期時間值 之間相差多少周(整數)
WeeksInAYear   返回指定的年有多少周
WeeksInYear   返回指定日期時間值的那年有多少周
WeekSpan   返回兩個指定日期時間值之間相差多少周(包含小數)
WithinPastDays   判斷兩個日期之間相差 是否在指定天數的范圍內
WithinPastHours   判斷兩個日期 時間值之間相差是否在指定小時的范圍內
WithinPastMilliSeconds   判斷兩個日期時間值之間相差是否在指定毫秒的范圍內
WithinPastMinutes   判斷兩個日期時間值之間相差是否在指定分鍾的范圍內
WithinPastMonths   判斷兩個日期時間值之間相差是否在指定月份的范圍內
WithinPastSeconds   判斷兩個日期時間值之間相差是否在指定秒數的范圍內
WithinPastWeeks   判斷兩個日期時間值之間相差是否在指定星期數的范圍內
WithinPastYears   判斷兩個日期時間值之間相差是否在指定年數的范圍內
YearOf   返回指定日期時間值中年份部分
YearsBetween   返回兩個指定日期時間值之間相差的年份數(整數)
YearSpan   返回兩個指定日期時間值之間相差的年份數(包含小數)
Yesterday 返回當前日期之前一天(昨天)的日期



***********julian date
  儒略日
  有效的日期范圍是從公元前4721年1月1日到公元9999年12月31日。儒略日(julian date)是自公元前4712年1月1日中午12時起經過的天數。
  用途:在一些mainframe系統中會用到這種日期格式。



yyyymmddhhmmss這種格式的字符串怎么轉換
DateToStr( StrToDate( Source, 'yyyymmddhhmmss' ), 'yyyy-mm-dd hh:mm:ss' )
很久不用Delphi了,可能有錯誤,但是用的就是那兩個函數

uses MaskUtils;
FormatMaskText('0000-00-00 00:00:00;0','20120621162601')

// 常用Delphi RTL函數
// ShowMessageFmt('%d, %d', [obj.Pos.X, obj.Pos.Y]);
// Trunc, RoundTo, Round

{
SysUtils
// 貨幣
CurrencyString: string;
CurrencyFormat: Byte;
CurrencyDecimals: Byte;
NegCurrFormat: Byte;
// 百十位
ThousandSeparator: Char;
DecimalSeparator: Char;
// 日期
DateSeparator: Char;
ShortDateFormat: string;
LongDateFormat: string;
// 時間
TimeSeparator: Char;
TimeAMString: string;
TimePMString: string;
ShortTimeFormat: string;
LongTimeFormat: string;
// 月名(當地語言)
ShortMonthNames: array[1..12] of string;
LongMonthNames: array[1..12] of string;
// 星期名(當地語言)
ShortDayNames: array[1..7] of string;
LongDayNames: array[1..7] of string;
// 其它
SysLocale: TSysLocale;
EraNames: array[1..7] of string;
EraYearOffsets: array[1..7] of Integer;
TwoDigitYearCenturyWindow: Word = 50;
ListSeparator: Char;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM