一个很简单的日期转换问题 我想把月日小时组合在一起组成一个字符串,比如今天是8月2日12点,就转换成字符串‘080212’,方法应该有很多种,大家列举几个比较好的方法,谢谢。在线等待。我使用了比如日期转换MONTHOF(NOW()),这样月份应该是提出来了,可是不知道如何转换成字符串。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 function FormatDateTime(const Format: string; DateTime: TDateTime): string; 1、Formatdatetime2、DecodeDate, DecodeTime,然后自己想拼成什么样就拼成什么样 你愿意的话慢慢的copy,用的人也看不出来的 楼上几位的方法都很好,用你们的方法问题已经解决。我想再问一下:我想把提取出来的时间保存到ARRAY OF CHAR型数组里边,存在一个类型转换的问题,比如说如何将formatdatetime('MMddHH',now)类型转换保存到ARRAY OF CHAR型数组里边 procedure TForm1.Button1Click(Sender: TObject);var Present: TDateTime; Year, Month, Day, Hour, Min, Sec, MSec: Word; str:string; begin Present:= Now; label1.Caption :=''; DecodeDate(Present, Year, Month, Day); DecodeTime(Present, Hour, Min, Sec, MSec); if length(inttostr(month))=1 then label1.Caption := '0'+inttostr(month) else label1.Caption :=inttostr(month); if length(inttostr(Day))=1 then label1.Caption := label1.Caption + '0' + inttostr(Day) else label1.Caption := label1.Caption + inttostr(Day); { if length(inttostr(year))=1 then label1.Caption := label1.Caption +'0'+inttostr(year) else label1.Caption := label1.Caption +inttostr(year); } if length(inttostr(hour))=1 then label1.Caption := label1.Caption +'0'+inttostr(hour) else label1.Caption := label1.Caption+inttostr(hour);{ if length(inttostr(Hour))=1 then label2.Caption := '0'+inttostr(Hour) else label2.Caption :=inttostr(Hour); if length(inttostr(Min))=1 then label2.Caption := label2.Caption + '0'+inttostr(Min) else label2.Caption := label2.Caption +inttostr(Min); if length(inttostr(Sec))=1 then label2.Caption := label2.Caption + '0'+inttostr(Sec) else label2.Caption := label2.Caption +inttostr(Sec); }end; procedure TForm1.Button2Click(Sender: TObject);beginedit1.Text :=formatdatetime('MMddHH',now);end; 我想把提取出来的时间保存到ARRAY OF CHAR型数组里边,存在一个类型转换的问题,比如说如何将formatdatetime('MMddHH',now)类型转换保存到ARRAY OF CHAR型数组里边有人知道吗? 一个关于utc时间的问题,求助大家! 【活躍論壇氣氛】之數據庫 会VC的老大帮我看看这个应该怎么翻译成Delphi的代码!!顶者有分! 为何DELPHI版中的基础类没有了? delphi5中的错误!急!!!!!在线等! 数据库类 registerclass的问题 win98下打开项目出现"非法操作"的情况! EAccess问题 雪地裸跪在线等解 好心人过节了帮帮忙 关于报表控件自动拖放 这个错误如何解决:"无法为更新定位行,一些值可能已在最后一次读取后已更改" ado和bde的探讨!~~~
2、DecodeDate, DecodeTime,然后自己想拼成什么样就拼成什么样
var
Present: TDateTime;
Year, Month, Day, Hour, Min, Sec, MSec: Word;
str:string;
begin
Present:= Now;
label1.Caption :='';
DecodeDate(Present, Year, Month, Day);
DecodeTime(Present, Hour, Min, Sec, MSec);
if length(inttostr(month))=1 then
label1.Caption := '0'+inttostr(month)
else
label1.Caption :=inttostr(month);
if length(inttostr(Day))=1 then
label1.Caption := label1.Caption + '0' + inttostr(Day)
else
label1.Caption := label1.Caption + inttostr(Day);
{ if length(inttostr(year))=1 then
label1.Caption := label1.Caption +'0'+inttostr(year)
else
label1.Caption := label1.Caption +inttostr(year); }
if length(inttostr(hour))=1 then
label1.Caption := label1.Caption +'0'+inttostr(hour)
else
label1.Caption := label1.Caption+inttostr(hour);
{ if length(inttostr(Hour))=1 then
label2.Caption := '0'+inttostr(Hour)
else
label2.Caption :=inttostr(Hour);
if length(inttostr(Min))=1 then
label2.Caption := label2.Caption + '0'+inttostr(Min)
else
label2.Caption := label2.Caption +inttostr(Min);
if length(inttostr(Sec))=1 then
label2.Caption := label2.Caption + '0'+inttostr(Sec)
else
label2.Caption := label2.Caption +inttostr(Sec); }
end;
beginedit1.Text :=formatdatetime('MMddHH',now);
end;
有人知道吗?