TDateTime详解
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
tdatetime为实现tdatetime数据类型和使用tdatetime数据类型的日期-时间运行库例程的c++类。
tdatetime类继承了double型的val数据成员,其中包含了日期-时间值。
tdatetime值的整数部分为自从12/30/1899以来的天数。
其小数部分为天的时间。
下列为一些tdatetime值的例子以及对应的日期和时间:
值日期和时间
0 12/30/1899 12:00 am
2.75 1/ 1/1900 6:00 pm
-1.25 12/29/1899 6:00 am
35065 1/ 1/1996 12:00 am
要计算两个日期间的天的小数部分,把两个值相减。
要在某天的小数部分增加一个日期-时间值,可把该小数加上日期-时间值。
方法列表
currentdate 返回当前日期作为tdatetime值
currentdatetime 返回当前日期和时间作为tdatetime 值
currenttime 返回当前时间作为tdatetime值
datestring 把tdatetime值的日期转换为一个字符串
datetimestring 把tdatetime值转换为一个字符串
dayofweek 返回tdatetime的week的天
decodedate 把tdatetime值分为year, month,和day值并把这些值分别存储在year, month和day参数中
decodetime 把tdatetime值分为hour, minute, second,和millisecond值并把这些值分别存储在hour, min, sec和msec参数中
filedate 把日期- 时间值转换为dos日期- 时间标记
filedatetodatetime 把filedate参数指定的dos文件的日期- 时间值转换为tdatetime值
formatstring 利用format给定的格式格式化tdatetime对象
operator - 返回两个tdatetime集之间的差的新的tdatetime对象
operator -- 返回一个tdatetime与int参数之间差的新的tdatetime对象
operator != 比较两个tdatetime对象的不相同性
operator + 返回一个为两个tdatetime对象的联合的一个新tdatetime 对象operator += 把tdatetime 对象的本身数据与rhs 指定的tdatetime对象的联合赋给tdatetime
operator -= 把tdatetime 对象本身数据的rhs指定的tdatetime对象之间的差赋给tdatetime对象
operator < 比较两个tdatetime 对象
operator <= 比较两个tdatetime 对象
operator = 把rhs 内容赋给tdatetime
operator == 比较两个tdatetime 对象的相同
operator > 比较两个tdatetime 对象
operator >= 比较两个tdatetime 对象
operator ansistring ansistring 为转换操作符
operator double double 为转换操作符
operator int int 为转换操作符
tdatetime tdatetime 构造函数
timestring 把tdatetime 对象转换为ansistring
方法
tdatetime::currentdate
返回当前日期作为tdatetime值。
static tdatetime __fastcall currentdate( );
检索当前日期并作为新的tdatetime 对象返回。
tdatetime::currentdatetime
返回当前日期和时间作为tdatetime值。
static tdatetime __fastcall currentdatetime( );
检索当前日期和时间并作为新的tdatetime 对象返回。
tdatetime::currenttime
返回当前时间作为tdatetime 值。
static tdatetime __fastcall currenttime( );
检索当前时间并作为新的tdatetime 对象返回。
tdatetime::datestring
把tdatetime 值的日期转换为一个字符串。
ansistring __fastcall datestring( )const;
返回tdatetime对象作为一个ansistring 的值。
转换利用shortdateformat 变量指定的格式。
tdatetime::datetimestring
把tdatetime 值转换为一个字符串。
ansistring __fastcall datetimestring( )const
返回一个ansistring 对象,其中包含tdatetime 对象的日期和时间(val 数据成员)转换为字符串的值。
如果tdatetime 值没有包含一个date 值,date 就显示为00/00/00。
如果tdatetime 值没有包含一个time值,time 就显示为00:00:00 am。
可以通过改变日期和时间格式变量来改变字符串格式。
tdatetime::dayofweek
返回tdatetime 的week的天。
int __fastcall dayofweek()const;
tdatetime 的dayofweek 对象为 1 到7 之间的整数。
sunday 为week 的第一天,saturday 为第七天。
tdatetime::decodedate
把tdatetime 值分为year ,month和day 值并把这些值分别存储在
year ,month 和day 参数中。
void __fastcall decodedate(unsigned short* year,unsigned short* month,unsigned short* day)const;
需要访问tdatetime对象的year, month 和day 时,利用decodedate。
tdatetime::decodetime
把tdatetime 值分为hour ,minute,second 和millisecond 值并把这些值分别存储在hour,min,sec 和msec参数中。
void __fastcall decodetime(unsigned shot* hour,unsigned short*nim,unsigned short* sec,unsigned short* msec)const;
需要访问tdatetime对象的hour,minute,second或millisecond时,利用decodedate。
tdatetime::filedate
把日期—时间值转换为dos日期—时间标记。
int __fastcall filedate()const;
tdatetime::filedatetodatetime
把filedate 参数指定的dos文件的日期—时间值转换为tdatetime值。
static tdatetime __fastcall filedatetodatetime(int filedate);
tdatetime::formatstring
利用format 给定的格式格式化tdatetime 对象。
ansistring __fastcall formatstring(const ansistring& format);
支持下列分类符字符串:
分类符字符串显示方式
c 日期使用shortdateformat全局变量给的格式,时间使用longtimeformat 全局变量给的格式。
假如分数是0,时间就不显示。
d 以数字表示日子,第一个字符不为0 (1—31)
dd 以数字表示日子,第一个字符为0 (01—31)
ddd 以使用shortdateformat全局变量给的字符串的缩写(sun—sat) g表示日子dddd 以使用long day names全局变量给的字符串的全称(sunday—saturday)表示日子
ddddd 使用shortdateformat全局变量给的格式表示日期
dddddd 使用long dateformat 全局变量给的格式表示日期
m 以数字表示月份,第一个字符不为0 (1—12)。
若m 后面跟着h或hh,显示的是分钟,而不是月份
mm 以数字表示月份,第一个字符为0(01—12)。
若mm 后面跟着h或hh,显示的是分钟,而不是月份。
mmm 以使用shortmonthnames 全局变量给的字符串的缩写( jan — dec)表示月份mmmm 以使用long mames 全局变量给的字符串的全称(january — decermber)表示月份
yy 以两位数字表示年(00—99)
yyyy 以四位数字表示年(0000—9999)
h 以数字表示小时,第一字符不为0(0—23)
hh 以数字表示小时,第一字符为0(0—23
n 以数字表示分钟,第一个字符不为0(0—59)
nn 以数字表示分钟,第一个字符为0(00—59)
s 以数字表示秒,第一个字符不为0(0—59)
ss 以数字表示秒,第一个字符为0(00—59)
t 时间使用由shorttimeformst全局变量给定的格式
ttt 时间使用由longtimeformat全局变量给定的格式
am/pm 时间为前面的h或hh分类符使用12小时时钟,后面跟"am"指的是上午的时间,后面跟"pm"指的是下午的时间。
am/pm分类符可以是大写、小写或混合使用,都能相应的显示
a/p 时间为前面的h或hh分类符使用12小时时钟,后面跟"a"指的是上午的时间,后面跟"p"指的是下午的时间。
a/p分类符可以是大写、小写或混合使用,都能相
应的显示
ampm 时间为前面的h或hh分类符使用12小时时钟,后面跟timeamstring 全局变量指的是上午的时间,后面跟timepmstring 全局变量指的是下午的时间
/ 由dateseparator 全局变量给定的日期分隔符:由timeseparator 全局变量给定的时间分隔符
'xx'/"xx" 用单引号或双引号括起的符号,表示不进行格式转换
格式分类符应写成大写或小写字母,两个产生同样效果。
假如格式参数指的是空字符串,日期时间值被格式化成格式分类符给的是c。
tdatetime::operator -
tdatetime的operator-被重载如下:
tdatetime __fastcall operator - (const tdatetimebase& rhs)const;
返回这个tdatetime 对象与rhs 的差。
tdatetime __fastcall operator - (const tdatetime& rhs)const;
返回两个tdatietime 对象的差。
tdatetime __fastcall operator - (const double rhs)const;
返回这个tdatetime 对象与double的rhs 的差。
tdatetime __fastcall operator - (const int rhs)const;
返回这个tdatetime 对象与int 的rhs 的差。
tdatetime::operator --
tdatetime的operator--被重载如下:
tdatetime& operator -- ( );
把这个tdatetime对象的日期减去一天(从val数据成员中减1)。
tdatetim。