???如何获得当前日期减一个月的值日期,如何获得当前时间减一个小时的时间,如何获得当前时间减一分钟的时间??? 如何获得当前日期(系统日期)减一个月的日期值,如何获得当前时间减一个小时的时间,如何获得当前时间减一分钟的时间请分别给出代码,可用2000-01-01 00:00:00 格式表示也可单独用日期或时间分开表示! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在DateUtils(d7)里,有如下几个现成的函数function IncYear(const AValue: TDateTime; const ANumberOfYears: Integer = 1): TDateTime;// function IncMonth is in SysUtilsfunction 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就可以得到了 varDateTime:TDateTime;sj:string;sj2:integer;beginDateTime:=now;sj:=DateToStr(DateTime) ;delete(sj,1,pos('-',sj));delete(sj,pos('-',sj),length(sj));sj2:=strtoint(sj)-1;showmessage('当前月份减去1个月为:'+inttostr(sj2)+'月');end; varDateTime:TDateTime;sj:string;sj2:integer;beginDateTime:=now;sj:=DateToStr(DateTime) ;delete(sj,1,pos('-',sj));delete(sj,pos('-',sj),length(sj));sj2:=strtoint(sj)-1;showmessage('当前月份减去1个月为:'+inttostr(sj2)+'月');end; var str:string;begin str:=formatdatetime('yymmddhh',now-1);end;now-30:当前时间减一月的时间now-1:当前时间减一天的时间now-1/24:当前时间减一小时的时间。类推就可以了 学习了扩冲例子如下: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; now-30:当前时间减一月的时间这个不对吧。 1楼的列出的不全,但的确DateUtils单元自带的函数可以解决你的问题。 学习,delphi中有关时间的问题值得讨论学习。 同意1楼,delphi自带的函数2楼是直接把时间做为浮点型的, uses DateUtils如何获得当前日期(系统日期)减一个月的日期值,IncMonth(now,-1);如何获得当前时间减一个小时的时间,IncHour(now,-1);如何获得当前时间减一分钟的时间 IncMinute(now,-1) delphi内的dbgrid导出到 EXCEL,为何老有现在打开的excel文档的数据,不仅仅是现在dbgrid内的数据! 动态连接库的简单问题 高分相送:DELPHI操作SQLSERVER时如何使用事务?? 数据导出Excell问题 一个很苯的问题,请高手教我! 真的是怪啊………… DELPHI7超简单问题? 旧话重提:在nt/2000下怎样获取硬盘的物理序列号(如果用到了组件或dll需要有代码)up有分 ============最近被这个问题搞得很狼狈================ C/s模式怎么开发啊? 利用VCL绘图,有内存释放问题吗? ListView组件问题
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就可以得到了
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;
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;
begin
str:=formatdatetime('yymmddhh',now-1);
end;now-30:当前时间减一月的时间
now-1:当前时间减一天的时间
now-1/24:当前时间减一小时的时间
。类推就可以了
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;
这个不对吧。
IncMonth(now,-1);如何获得当前时间减一个小时的时间,
IncHour(now,-1);如何获得当前时间减一分钟的时间
IncMinute(now,-1)