delphi DateUtils函数

来源:互联网 发布:淘宝网买东西注意什么 编辑:程序博客网 时间:2024/04/28 18:34
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;

0 0
原创粉丝点击