Delphi 日期时间函数

定义 说明
Date():TDateTime 返回当前日期  
Time():TDateTime 返回当前时间  
Now():TDateTime 返回当前日期时间  
CurrentYear():Word 返回当前年份  
IsLeapYear(Year: Word): Boolean 返回是否闰年  
DayOfWeek(const TDateTime): Word 返回星期数,星期天=1  
EncodeDate(Year, Month, Day: Word): TDateTime 合并年、月、日  
EncodeTime(Hour, Min, Sec, MSec: Word): TDateTime 合并时、分、秒  
TryEncodeDate(Year, Month, Day: Word; out TDateTime) 合并年、月、日,返回是否成功  
TryEncodeTime(Hour, Min, Sec, MSec: Word; out TDateTime): TDateTime 合并时、分、秒,返回是否成功  
DecodeDate(TDateTime; var Year, Month, Day: Word); 分解年、月、日  
DecodeDateFully(TDateTime; var Year, Month, Day, DOW: Word) 分解年、月、日、星期  
InternalDecodeDate(TDateTime; var Year, Month, Day, DOW: Word)    
DecodeTime(TDateTime; var Hour, Min, Sec, MSec: Word); 分解时、分、秒、微秒  
IncMonth(constTDateTime; Integer = 1): TDateTime 返回增加若干月后的日期时间  
IncMonth(constTDateTime; Integer = 1): TDateTime 返回增加若干月后的日期时间  
IncAMonth(var Year, Month, Day: Word; NumberOfMonths: Integer = 1) 计算增加若干月的年、月、日  
ReplaceTime(var TDateTime,TDateTime) 替换时间部分  
ReplaceDate(var TDateTime,TDateTime) 替换日期部分  

日期时间转换函数

定义 说明
DateToStr(TDateTime):String

TimeToStr(TDateTime):String

DateTimeToStr(TDateTime):String

日期时间转字符串 SysUtils
StrToDateTime(String):TDateTime

StrToDate(String):TDateTime

StrToTime(String):TDateTime

字符串转日期时间 SysUtils
DateTimeTOTimeStamp(TDateTime):TTimeStamp 日期时间转时间结构  
TimeStampTODateTime(TTimeStamp):TDateTime 时间结构转日期时间  
MSecsToTimeStamp(Comp):TTimeStamp 微秒转为时间结构  
TimeStampToMSecs(TTimeStamp):Comp 时间结构转为微秒  
DateTimeToSystemTime(TDateTime; var TSystemTime) 日期时间转系统时间  
SystemTimeToDateTime(TSystemTime): TDateTime 系统时间转日期时间  
DateToStr(const TDateTime): string 日期转字符串  
TimeToStr(const TDateTime): string 时间转字符串  
DateTimeToStr(const TDateTime): string 日期时间转字符串  
StrToDate(const string): TDateTime 字符串转日期  
StrToDateDef(const string,def): TDateTime 字符串转日期,提供默认值  
TryStrToDate(const string,out TDateTime) 字符串转日期,返回是否成功  
StrToTime(const string): TDateTime 字符串转时间  
StrToTimeDef(const string,def): TDateTime 字符串转时间,提供默认值  
TryStrToTime(const string,out TDateTime) 字符串转时间,返回是否成功  
StrToDateTime(const string): TDateTime 字符串转日期时间  
StrToDateTimeDef(const string,def): TDateTime 字符串转日期时间,提供默认值  
TryStrToDateTime(const string,out TDateTime) 字符串转日期时间,返回是否成功  
FileDateToDateTime(integer):TDateTime 文件时间整数转为日期时间型  
DateTimeToFileDate(TDateTime):Integer 日期时间型 TDateTime 转为文件时间整数