我想把月日小时组合在一起组成一个字符串,比如今天是8月2日12点,就转换成字符串‘080212’,方法应该有很多种,大家列举几个比较好的方法,谢谢。在线等待。
我使用了比如日期转换MONTHOF(NOW()),这样月份应该是提出来了,可是不知道如何转换成字符串。

解决方案 »

  1.   

    function FormatDateTime(const Format: string; DateTime: TDateTime): string;
      

  2.   

    1、Formatdatetime
    2、DecodeDate, DecodeTime,然后自己想拼成什么样就拼成什么样
      

  3.   

    你愿意的话慢慢的copy,用的人也看不出来的
      

  4.   

    楼上几位的方法都很好,用你们的方法问题已经解决。我想再问一下:我想把提取出来的时间保存到ARRAY OF CHAR型数组里边,存在一个类型转换的问题,比如说如何将formatdatetime('MMddHH',now)类型转换保存到ARRAY OF CHAR型数组里边
      

  5.   

    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;
      

  6.   

    procedure TForm1.Button2Click(Sender: TObject);
    beginedit1.Text :=formatdatetime('MMddHH',now);
    end;
      

  7.   

    我想把提取出来的时间保存到ARRAY OF CHAR型数组里边,存在一个类型转换的问题,比如说如何将formatdatetime('MMddHH',now)类型转换保存到ARRAY OF CHAR型数组里边
    有人知道吗?