如何显示年和月,不显示日  2006-01  这个样子,用format属性,但是,yyyy-mm中yyyy不好用,另外,得到日期后,如何算出,选择的日期与现在相差多少年最后问个小问题。  如何让输入框(text)中,只能输入:数字和"."(小数点)

解决方案 »

  1.   

    1.用FormatDateTime函数:FormatDateTime('yyyy-mm',Now)2.用DateUtils单元的YearsBetween函数3.Edit的OnKeyPress事件: procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
      if not( Key in['0'..'9','.',#8]) then Key:=#0;
    end;
      

  2.   

    1.用FormatDateTime函数:FormatDateTime('yyyy-mm',Now)2.用DateUtils单元的YearsBetween函数大哥,1,2能不能具体点,我是出学者,给几句代码吧。
      

  3.   

    1
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      ShowMessage(FormatDateTime('yyyy-mm',Now));
    end;2  uses DateUtils;procedure TForm1.Button2Click(Sender: TObject);
    var t1,t2:TDateTime;
    begin
      t1:=StrToDateTime('1990-1-1');
      t2:=StrToDateTime('2006-1-1');
      ShowMessage('相差'+IntToStr(YearsBetween(t1,t2))+'年');
    end;已经很详细了,如果还不懂的话,要去找本Delphi入门的书来看看了。
      

  4.   

    格式化日期用
    function FormatDateTime(const Format: string; DateTime: TDateTime): string; const参数:
    c 以短时间格式显示时间
    d 对应于时间中的日期
    dd 和d的意义一样,但以两位来显示
    ddd 显示的是汉字星期几
    ddddd 以短时间格式显示年月日
    dddddd 以长时间格式显示年月日
    e/ee/eee/eeee 以相应的位数显示年
    m/mm/mmm/mmmm 表示月yy/yyyy 表示年  h/hh,n/nn,s/ss,z/zzz 分别表示小时,分,秒,毫秒
    t  以短时间格式显示时间
    tt 以长时间格式显示时间
    ampm 以长时间格式显示上午还是下午
      

  5.   

    liangqingzhi(老之) 太厉害了。
    接分。