var time: array[0..5] of integer; begin time[0]:=yaerof(DateTimePicker1.DateTime); time[1]:=MonthOf(DateTimePicker1.DateTime); time[2]:=dayof(DateTimePicker1.DateTime); time[3]:=HourOf(DateTimePicker1.DateTime); time[4]:=MinuteOf(DateTimePicker1.DateTime); time[5]:=SecondOf(DateTimePicker1.DateTime);end;要用到DateUtils单元,还有很多时间的函数,自己查帮助
可以这样 formatdatetime('hh:mm:ss',dtpTime1.time);
呵呵,还是用DECODEDATETIME吧!!!!!!procedure DecodeDateTime(const AValue: TDateTime; out AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond: Word);DescriptionThe DecodeDateTime procedure breaks the value specified as the AValue parameter into Year, Month, Day of the month, Hour, Minute, Second, and MilliSecond values and returns these as the AYear, AMonth, ADay, AHour, AMinute, ASecond, and AMilliSecond parameters.我想只有用这个过程;了!!!
格式化成字符串了,然后通过Copy方式分别Copy出年,月,日来
FormatDateTime('hhmmss', dtpTime1.DateTime)
方法同上
dtpDate.GetTime(&dTime);
int iYear=dTime.GetYear();
int iMonth=dTime.GetMonth();
int iDay=dTime.GetTime();
....
其中str为要复制的字符串,从第m个字符开始,copy n个字符
如copy('asdfg',3,2)的结果为df;
不过delphi提供了好多有关时间的函数,可以直接使用
FormatDateTime('mm', dtpTime1.DateTime);
FormatDateTime('dd', dtpTime1.DateTime);
FormatDateTime('hh', dtpTime1.DateTime)
begin
time[0]:=yaerof(DateTimePicker1.DateTime);
time[1]:=MonthOf(DateTimePicker1.DateTime);
time[2]:=dayof(DateTimePicker1.DateTime);
time[3]:=HourOf(DateTimePicker1.DateTime);
time[4]:=MinuteOf(DateTimePicker1.DateTime);
time[5]:=SecondOf(DateTimePicker1.DateTime);end;要用到DateUtils单元,还有很多时间的函数,自己查帮助
formatdatetime('hh:mm:ss',dtpTime1.time);
就用 formatdatetime 来做吧!~~~~
如果你不嫌麻烦
FormatDateTime('yyyy', dtpDate.DateTime);
FormatDateTime('mm', dtpDate.DateTime);
FormatDateTime('dd', dtpDate.DateTime);
FormatDateTime('hh', dtpDate.DateTime);//如果错误就用now
FormatDateTime('mm', dtpDate.DateTime);
FormatDateTime('ss', dtpDate.DateTime);
然后你需要定义三个 word 类型的值来存放
year,month,day
都可解决呀!!!!
DecodeDateTime
函数可以用。
使用DATEPART函数~
Year, Month, Day, Hour, Min, Sec, MSec: Word;
begin
DecodeDate(DateTimePicker1.DateTime, Year, Month, Day);
Label1.Caption := 'Today is Day ' + IntToStr(Day) + ' of Month '
+ IntToStr(Month) + ' of Year ' + IntToStr(Year);
DecodeTime(DateTimePicker1.DateTime, Hour, Min, Sec, MSec);
Label2.Caption := 'The time is Minute ' + IntToStr(Min) + ' of Hour '
+ IntToStr(Hour);
end;
Present: TDateTime;
Year, Month, Day, Hour, Min, Sec, MSec: Word;
begin
Present:= Now;
DecodeDate(Present, Year, Month, Day);
Label1.Caption := 'Today is Day ' + IntToStr(Day) + ' of Month '
+ IntToStr(Month) + ' of Year ' + IntToStr(Year);
DecodeTime(Present, Hour, Min, Sec, MSec);
Label2.Caption := 'The time is Minute ' + IntToStr(Min) + ' of Hour '
+ IntToStr(Hour);
end;