注册 登录
编程论坛 Delphi论坛

如何获取?

qpfmates 发布于 2008-10-29 14:28, 1269 次点击
如何获取系统时间,如何获取系统日期?
5 回复
#2
ruanjian21102008-10-29 15:24
var
 ADate:TDateTime;
 ss:string;
 week:array[1..7]of  string;
 begin
   week[1]:='星期天';
   week[2]:='星期一';
   week[3]:='星期二';
   week[4]:='星期三';
   week[5]:='星期四';
   week[6]:='星期五';
   week[7]:='星期六';
   ADate:=strtodate(FormatDateTime('yyyy-mm-dd',now));
   ss:=FormatDateTime('yyyy"年"m"月"d"日"hh:nn:ss',now);
   Edit1.Text:='当前日期:'+ss+#0+week[DayOfWeek(ADate)];
 end;
#3
dudu31182008-11-10 21:06
回帖是一种美德!每次回帖即可获得 10 分可用积分!只看帖不回帖鄙视你。
用心参与大家的技术讨论,将有机会在每月的全民选举中获得 1-3 个威望。
#4
dudu31182008-11-10 21:43
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Button1: TButton;
    Button2: TButton;
    Timer1: TTimer;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
 Timer1.Enabled:=true;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 Timer1.Enabled:=false;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
 var
    DateTime : TDateTime;
     Year, Month, Day, Hour, Min, Sec, MSec: Word;
  begin
   DateTime:= Now;
   DecodeDate(DateTime, Year, Month, Day);
   Label1.Caption:='Year: '+Inttostr(Year);
   Label2.Caption:='Month: '+Inttostr(Month);
   Label3.Caption:='Day: '+Inttostr(Day);
   DecodeTime(DateTime, Hour, Min, Sec, MSec);
   Label4.Caption:='Hour: '+Inttostr(Hour);
   Label5.Caption:='Min: '+Inttostr(Min);
   Label6.Caption:='Sec: '+Inttostr(Sec);
   Label7.Caption:='MSec: '+Inttostr(Msec)
end;

end.
#5
qpfmates2008-11-12 19:50
谢谢了!
#6
cwb198708022009-07-28 19:38
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Button1: TButton;
    Button2: TButton;
    Timer1: TTimer;
  
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}



procedure TForm1.Button1Click(Sender: TObject);
begin
Timer1.Enabled:=true;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Timer1.Enabled:=false;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
    DateTime : TDateTime;
     Year, Month, Day, Hour, Min, Sec, MSec: Word;
  begin
   DateTime:= Now;
   DecodeDate(DateTime, Year, Month, Day);
   Label1.Caption:='Year: '+Inttostr(Year);
   Label2.Caption:='Month: '+Inttostr(Month);
   Label3.Caption:='Day: '+Inttostr(Day);
   DecodeTime(DateTime, Hour, Min, Sec, MSec);
   Label4.Caption:='Hour: '+Inttostr(Hour);
   Label5.Caption:='Min: '+Inttostr(Min);
   Label6.Caption:='Sec: '+Inttostr(Sec);
   Label7.Caption:='MSec: '+Inttostr(Msec);


end;

procedure TForm1.FormCreate(Sender: TObject);
begin

end;

end.
1