如何获得当前日期(系统日期)减一个月的日期值,如何获得当前时间减一个小时的时间,如何获得当前时间减一分钟的时间请分别给出代码,可用2000-01-01 00:00:00 格式表示也可单独用日期或时间分开表示!

解决方案 »

  1.   

    在DateUtils(d7)里,有如下几个现成的函数
    function IncYear(const AValue: TDateTime;
      const ANumberOfYears: Integer = 1): TDateTime;
    // function IncMonth is in SysUtils
    function IncWeek(const AValue: TDateTime;
      const ANumberOfWeeks: Integer = 1): TDateTime;
    function IncDay(const AValue: TDateTime;
      const ANumberOfDays: Integer = 1): TDateTime;
    function IncHour(const AValue: TDateTime;
      const ANumberOfHours: Int64 = 1): TDateTime;
    function IncMinute(const AValue: TDateTime;
      const ANumberOfMinutes: Int64 = 1): TDateTime;
    function IncSecond(const AValue: TDateTime;
      const ANumberOfSeconds: Int64 = 1): TDateTime;
    function IncMilliSecond(const AValue: TDateTime;
      const ANumberOfMilliSeconds: Int64 = 1): TDateTime;
    你把增加的值设置成-1就可以得到了
      

  2.   

    var
    DateTime:TDateTime;
    sj:string;
    sj2:integer;
    begin
    DateTime:=now;
    sj:=DateToStr(DateTime)  ;
    delete(sj,1,pos('-',sj));
    delete(sj,pos('-',sj),length(sj));
    sj2:=strtoint(sj)-1;
    showmessage('当前月份减去1个月为:'+inttostr(sj2)+'月');
    end;
      

  3.   

    var
    DateTime:TDateTime;
    sj:string;
    sj2:integer;
    begin
    DateTime:=now;
    sj:=DateToStr(DateTime)  ;
    delete(sj,1,pos('-',sj));
    delete(sj,pos('-',sj),length(sj));
    sj2:=strtoint(sj)-1;
    showmessage('当前月份减去1个月为:'+inttostr(sj2)+'月');
    end;
      

  4.   

    var str:string;
    begin
       str:=formatdatetime('yymmddhh',now-1);
    end;now-30:当前时间减一月的时间
    now-1:当前时间减一天的时间
    now-1/24:当前时间减一小时的时间
    。类推就可以了
      

  5.   

    学习了扩冲例子如下:
    var
      str:string;
      d:TDateTime;
    begin
      d:=now;            
      //yyyy-m-d h:n:s:zz 格式化组成:年-月-日 时:分:秒:毫秒
      ShowMessage('当前时间:'+DateTimeToStr(d));  str:=FormatDateTime('yyyy-mm-dd h:n:s:zz',d-1); //取得当前时间减一天
      ShowMessage('当前时间减一天:'+str);  str:=FormatDateTime('yyyy-mm-dd h:n:s:zz',d-30); //取得当前时间减一月
      ShowMessage('当前时间减一月:'+str);  str:=FormatDateTime('yyyy-mm-dd h:n:s:zz',d-1/24); //取得当前时间减一小时
      ShowMessage('当前时间减一小时:'+str);  str:=FormatDateTime('yyyy-mm-dd h:n:s:zz',d-1/24/60); //取得当前时间减一分钟 
      ShowMessage('当前时间减一分钟:'+str);  str:=FormatDateTime('yyyy-mm-dd h:n:s:zz',d-1/24/60/1000/60); //取得当前时间减一毫秒
      ShowMessage('当前时间减一毫秒:'+str);
    end;
      

  6.   

    now-30:当前时间减一月的时间
    这个不对吧。
      

  7.   

    1楼的列出的不全,但的确DateUtils单元自带的函数可以解决你的问题。
      

  8.   

    学习,delphi中有关时间的问题值得讨论学习。
      

  9.   

    同意1楼,delphi自带的函数2楼是直接把时间做为浮点型的,
      

  10.   

    uses DateUtils如何获得当前日期(系统日期)减一个月的日期值,
    IncMonth(now,-1);如何获得当前时间减一个小时的时间,
    IncHour(now,-1);如何获得当前时间减一分钟的时间 
    IncMinute(now,-1)