关于时间函数

王朝delphi·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

【0】在工程文件中Application.Run语句之前加入下面语句,可不让主Form在运行时显示:

Application.ShowMainForm := False;

【1】显示设置时间的对话框

ShellExecute(Handle, 'open', 'control', 'date/time', nil, SW_SHOW);

【2】FormatDateTime('yyyy mmmm',MyDate) 返回如【2008 十二月】

【3】//获得日期 Date := Trunc( DateTime );

//获得时间 Time := Frac( DateTime );

【3】计算任意月份的天数

procedure TForm1.Button10Click(Sender: TObject);

function DaysInMonth(ADate:TDateTime):Integer;

var MyYear,MyMonth,MyDay : Word;

MyDayTable : TDayTable;

tmpBool : Boolean;

begin

DecodeDate(ADate, MyYear, MyMonth, MyDay);

tmpBool := IsLeapYear(MyYear);

MyDayTable := MonthDays[tmpBool];

Result := MyDayTable[MyMonth];

end;

var MyDate : TDateTime; tmpStr : String; tmpInt : Integer;

begin

MyDate := strToDateTime('2003-12-01');

tmpStr := FormatDateTime('yyyy mmmm',MyDate);

tmpInt := DaysInMonth(MyDate);

ShowMessage(tmpStr + ' 有 ' + IntToStr(tmpInt) + 'ìì');

end;

【3】改变系统时间

1、定义变量

var SystemTime: TSystemTime;

2、转换日期

DateTimeToSystemTime(StrToDatetime('1999-09-01 11:12:12' ),SystemTime);

3、改变系统日期

SetSystemTime(SystemTime);

到此系统日期已经改变,可是由于API函数SetSystemTime()本身存在的BUG,

在你改变系统日期以后,等待一会,你会看到系统的日期是对的,可是时间却错了,

并不是我们设定的11:12:12,这样的问题看来需要微软才能解决了

///////////////////// 方法二 /////////////////////////

{ SetDate sets the current date in the operating system. Valid }

{ parameter ranges are: Year 1980-2099, Month 1-12 and Day }

{ 1-31. If the date is not valid, the function call is ignored. }

procedure SetDate(Year, Month, Day: Word); assembler;

asm

MOV CX,Year

MOV DH,BYTE PTR Month

MOV DL,BYTE PTR Day

MOV AH,2BH

INT 21H

end;

{ SetTime sets the time in the operating system. Valid }

{ parameter ranges are: Hour 0-23, Minute 0-59, Second 0-59 and }

{ Sec100 (hundredths of seconds) 0-99. If the time is not }

{ valid, the function call is ignored. }

procedure SetTime(Hour, Minute, Second, Sec100: Word); assembler;

asm

MOV CH,BYTE PTR Hour

MOV CL,BYTE PTR Minute

MOV DH,BYTE PTR Second

MOV DL,BYTE PTR Sec100

MOV AH,2DH

INT 21H

end;

function SetSystemDateTime(Year, Month, Day, Hour, Minute, Second: word): integer; export;

begin

SetDate(Year, Month, Day);

SetTime(Hour, Minute + 1, Second, 0);

result := 1;

end;

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航