如何将DateTimePicker的年月日时分秒分别取出来?

mikejakeson 2003-04-16 03:17:18
然后存到一个数组里, 我用两个DateTimePicker控件,请问如何实现?先谢了
...全文
1245 28 打赏 收藏 转发到动态 举报
写回复
用AI写文章
28 条回复
切换为时间正序
请发表友善的回复…
发表回复
「已注销」 2003-05-04
  • 打赏
  • 举报
回复
var
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;
lf43 2003-05-04
  • 打赏
  • 举报
回复
如果不行就用DECODEDATETIME吧
pinkstone 2003-05-04
  • 打赏
  • 举报
回复
支持楼上,用decode
cxfxs 2003-05-04
  • 打赏
  • 举报
回复
用DeCodeDate()和DeCodeTime()

var
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;
hnhhcj 2003-05-04
  • 打赏
  • 举报
回复
关注ing
zzzl 2003-05-03
  • 打赏
  • 举报
回复
你想不想用sql语句实现啊?
使用DATEPART函数~
boy2002 2003-05-03
  • 打赏
  • 举报
回复
decodedate()
decodetime()
Maxwell 2003-05-02
  • 打赏
  • 举报
回复

DecodeDateTime
函数可以用。
3CL 2003-05-01
  • 打赏
  • 举报
回复
这个问题你问了很久了,还没解决吗,我认为我的方法 和formatdatetime
都可解决呀!!!!
xiaoyuer0851 2003-05-01
  • 打赏
  • 举报
回复
其实用 DecodeDateTime()就可以了
然后你需要定义三个 word 类型的值来存放
year,month,day
tpmao 2003-04-16
  • 打赏
  • 举报
回复
呵呵,可是用DecodeDateTime()函数只要一句就可以了,楼主可以试一试!!!:)!
xiaoyuer0851 2003-04-16
  • 打赏
  • 举报
回复
呵呵,楼上的都已经回答完了,
就用 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);
tpmao 2003-04-16
  • 打赏
  • 举报
回复
不过,你还要把,AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond 这些返回的变量进行数据类型转换一下!!!!!1
tpmao 2003-04-16
  • 打赏
  • 举报
回复
呵呵,还是用DECODEDATETIME吧!!!!!!

procedure DecodeDateTime(const AValue: TDateTime; out AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond: Word);

Description

The 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.

我想只有用这个过程;了!!!
youcheng1 2003-04-16
  • 打赏
  • 举报
回复
可以这样
formatdatetime('hh:mm:ss',dtpTime1.time);
Frend 2003-04-16
  • 打赏
  • 举报
回复
up
qwertyasd 2003-04-16
  • 打赏
  • 举报
回复
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单元,还有很多时间的函数,自己查帮助
xzq111 2003-04-16
  • 打赏
  • 举报
回复
decodedata()
delphiyesgood 2003-04-16
  • 打赏
  • 举报
回复
试试:FormatDateTime('yyyy', dtpDate.DateTime)
FormatDateTime('mm', dtpTime1.DateTime);
FormatDateTime('dd', dtpTime1.DateTime);
FormatDateTime('hh', dtpTime1.DateTime)
xagw 2003-04-16
  • 打赏
  • 举报
回复
copy(str,m,n)
其中str为要复制的字符串,从第m个字符开始,copy n个字符
如copy('asdfg',3,2)的结果为df;
不过delphi提供了好多有关时间的函数,可以直接使用
加载更多回复(8)

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧