转回来的,还没实验:(btw什么叫up?)在DELPHI下读取与设置系统时钟
  
  可能很多朋友都想在自己的程序中显示系统时间,这在DELPHI中十分容易,利用DateToStr(Date)及
TimeToStr(Time)函数即可实现。二者的函数原型如下:
  functiom DateToStr(Date:TDateTime):string;
  function TimeToStr(Time:TDateTime):string;  其返回值均为String型。在程序中我们可以这样使用:
  Label1.Caption:=DateToStr(Date);
  Lable2.Caption:=TimeToStr(Time);  二者分别调用了Delphi函数Date和Time读取系统日期和时间来实现的,但只能读系统时钟,而不能设置系统
时钟。那么如何处理这一问题呢?这正是本文所要讨论的问题。  既然Delphi没有提供如此功能,但Delphi提供了调用WindowsAPI的接口。所以我们可以调用WindowsAPI函数
来实现这一功能。具体方法如下:
  procedure TForm1.Button1Click(Sender:TObject);
  begin
     Edit1.Text:='97/10/30 10:09:59'; //注意:控制面板内时间格式要为YY/MM/D
D
  end;  procedure TForm1.Button2Click(Sender:TObject);
  var
    systemtime:Tsystemtime;
    DateTime:TDateTime;
  begin
    DateTime:=StrToDateTime(Edit1.text); //获得时间(TDateTime格式)
    DateTimeToSystemTime(DateTime,systemtime);  //把Delphi的TDateTime格式转化为
API的TSystemTime格式 
     SetLocalTime(SystemTime);         //设置系统时间  
    GetLocalTime(SystemTime);       //读取系统时间
    DateTime:=SystemTimeToDateTime(SystemTime);  //把API的TSystemTime格式 转化
为 Delphi的TDateTime格式
    Edit2.Text:=DateTimeToStr(DateTime); //显示当前系统的时间
  end;  另外,还有好多其它的Delphi函数和API函数供我们使用,如:
  StrToDate、StrToTime、DateTimeToStr、StrToDateTime、DateTimeToSystemTime、Sy
stemTimeToDateTime、DateTimeToTimeStamp、TimeStampToDateTimeCompareFileTime、DosD
ateTimeToFileTime、FileTimeToDosDateTime、FileTimeToLocalFileTime、FileTimeToSyst
emTime、GetFileTime、SetFileTime、GetSystemTime(格林威治时间)、SetSystemTime.Get
SystemTimeAdjustment,SetSystemTimdAdjustment。//Rainbow的话:
//TSystemTime的格式
  PSystemTime = ^TSystemTime;
  TSystemTime = record
    wYear: Word;
    wMonth: Word;
    wDayOfWeek: Word; //当前的系统时间是星期几
    wDay: Word;
    wHour: Word;
    wMinute: Word;
    wSecond: Word;
    wMilliseconds: Word;
  end;
//TDateTime的格式
  TDateTime = type Double  具体我们可以查Delphi所带的Win32.HLP(WindowsAPI帮助文件),它在Delphi2.0ιHelp或Delphi3ιHelp目
录下可以找到。

解决方案 »

  1.   

    var   
        systemtime:Tsystemtime;
      DateTime:TDateTime;
    begin
      DateTime:=StrToDateTime(Edit1.text); //获得时间(TDateTime格式)
      DateTimeToSystemTime(DateTime,systemtime); //把Delphi的TDateTime格式转化为API的TSystemTime格式
      SetLocalTime(SystemTime); //设置系统时间
      GetLocalTime(SystemTime); //读取系统时间
      DateTime:=SystemTimeToDateTime(SystemTime); //把API的TSystemTime格式 转化为 Delphi的TDateTime格式
      Edit2.Text:=DateTimeToStr(DateTime); //显示当前系统的时间
    end;//TSystemTime的格式
    PSystemTime = ^TSystemTime;
    TSystemTime = record
     wYear: Word;
     wMonth: Word;
     wDayOfWeek: Word;  wDay: Word;
     wHour: Word;
     wMinute: Word;
     wSecond: Word;
     wMilliseconds: Word;
    end;
      

  2.   

    SetSystemTime就可以修改系统时间!
    喳喳帮助就可以了很简单的。
      

  3.   

    TimeToStr(Time)函数即可实现。二者的函数原型如下:
      functiom DateToStr(Date:TDateTime):string;
      function TimeToStr(Time:TDateTime):string;  其返回值均为String型。在程序中我们可以这样使用:
      Label1.Caption:=DateToStr(Date);
      Lable2.Caption:=TimeToStr(Time);  二者分别调用了Delphi函数Date和Time读取系统日期和时间来实现的,但只能读系统时钟,而不能设置系统
    时钟。那么如何处理这一问题呢?这正是本文所要讨论的问题。  既然Delphi没有提供如此功能,但Delphi提供了调用WindowsAPI的接口。所以我们可以调用WindowsAPI函数
    来实现这一功能。具体方法如下:
      procedure TForm1.Button1Click(Sender:TObject);
      begin
         Edit1.Text:='97/10/30 10:09:59'; //注意:控制面板内时间格式要为YY/MM/D
    D
      end;  procedure TForm1.Button2Click(Sender:TObject);
      var
        systemtime:Tsystemtime;
        DateTime:TDateTime;
      begin
        DateTime:=StrToDateTime(Edit1.text); //获得时间(TDateTime格式)
        DateTimeToSystemTime(DateTime,systemtime);  //把Delphi的TDateTime格式转化为
    API的TSystemTime格式 
         SetLocalTime(SystemTime);         //设置系统时间  
        GetLocalTime(SystemTime);       //读取系统时间
        DateTime:=SystemTimeToDateTime(SystemTime);  //把API的TSystemTime格式 转化
    为 Delphi的TDateTime格式
        Edit2.Text:=DateTimeToStr(DateTime); //显示当前系统的时间
      end;  另外,还有好多其它的Delphi函数和API函数供我们使用,如:
      StrToDate、StrToTime、DateTimeToStr、StrToDateTime、DateTimeToSystemTime、Sy
    stemTimeToDateTime、DateTimeToTimeStamp、TimeStampToDateTimeCompareFileTime、DosD
    ateTimeToFileTime、FileTimeToDosDateTime、FileTimeToLocalFileTime、FileTimeToSyst
    emTime、GetFileTime、SetFileTime、GetSystemTime(格林威治时间)、SetSystemTime.Get
    SystemTimeAdjustment,SetSystemTimdAdjustment。//Rainbow的话:
    //TSystemTime的格式
      PSystemTime = ^TSystemTime;
      TSystemTime = record
        wYear: Word;
        wMonth: Word;
        wDayOfWeek: Word; //当前的系统时间是星期几
        wDay: Word;
        wHour: Word;
        wMinute: Word;
        wSecond: Word;
        wMilliseconds: Word;
      end;
    //TDateTime的格式
      TDateTime = type Double
    var   
        systemtime:Tsystemtime;
      DateTime:TDateTime;
    begin
      DateTime:=StrToDateTime(Edit1.text); //获得时间(TDateTime格式)
      DateTimeToSystemTime(DateTime,systemtime); //把Delphi的TDateTime格式转化为API的TSystemTime格式
      SetLocalTime(SystemTime); //设置系统时间
      GetLocalTime(SystemTime); //读取系统时间
      DateTime:=SystemTimeToDateTime(SystemTime); //把API的TSystemTime格式 转化为 Delphi的TDateTime格式
      Edit2.Text:=DateTimeToStr(DateTime); //显示当前系统的时间
    end;//TSystemTime的格式
    PSystemTime = ^TSystemTime;
    TSystemTime = record
     wYear: Word;
     wMonth: Word;
     wDayOfWeek: Word;  wDay: Word;
     wHour: Word;
     wMinute: Word;
     wSecond: Word;
     wMilliseconds: Word;
    end;