中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > Delphi > 临时文章
关于时间函数
作者:LuckyJan 时间:2002-09-26 11:40 出处:互联网 责编:chinaitpower
              摘要:关于时间函数

【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;


关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有