delphi API使用例子,日期时间等

unit Unit3;

interface

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

type
  TForm3 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Memo1: TMemo;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form3: TForm3;

implementation

{$R *.dfm}

procedure TForm3.Button1Click(Sender: TObject);
begin
  ShowMessage('ok');
  Abort;
  ShowMessage('hehe');
end;

procedure TForm3.Button2Click(Sender: TObject);
var
  ret: Integer;
  date: TDateTime;
  str: string;
  timeStamp: TTimeStamp;
begin
  ret := AnsiCompareStr('hehe', 'hehe');
  ShowMessage(IntToStr(ret));
  ret := DateTimeToFileDate(Now());
  ShowMessage(IntToStr(ret));

  ShowMessage('timeStamp');
  timeStamp := DateTimeToTimeStamp(Now());
  ShowMessage(IntToStr(timeStamp.Time));
  ShowMessage(IntToStr(timeStamp.date));

  date := FileDateToDateTime(ret);
  ShowMessage(DateTimeToStr(date));
  ShowMessage(DateToStr(date));
  // DateTimeToString(str,'%d',date);
  // str:=FormatDateTime('',date);

  ShowMessage('Date:' + DateToStr(date));

end;

procedure TForm3.Button3Click(Sender: TObject);
var
  present: TDateTime;
  year, month, day, hour, min, sec, msec: Word;
begin
  present := Now;
  DecodeDate(present, year, hour, day);
  Memo1.Lines.Clear;
  Memo1.Lines.Add('Today is Day ' + IntToStr(day) + ' of Month ' + IntToStr
      (month) + ' of Year ' + IntToStr(year));

  DecodeTime(present, hour, min, msec, msec);
  Memo1.Lines.Add('The time is Minute ' + IntToStr(min) + ' of Hour ' + IntToStr
      (hour));

  Memo1.Lines.Add(IntToStr(year) + '-' + IntToStr(month) + '-' + IntToStr(day)
      + ' ' + IntToStr(hour) + ':' + IntToStr(min) + ':' + IntToStr(sec)
      + ':' + IntToStr(msec));
  DllregisterServer;
  DllUnregisterServer;
end;

procedure TForm3.Button4Click(Sender: TObject);
var
  path: string;
begin
  path := 'I:\IT\资料\技术帮助文档chm\android\test.txt';
  path := DOsPathToUnixPath(path);
  ShowMessage(path);

end;

procedure TForm3.Button5Click(Sender: TObject);
var
  MyDate, MyTime: TDateTime;
begin
  MyDate := EncodeDate(2013, 12, 31);
  Memo1.Lines.Add(DateToStr(MyDate));
  MyTime := EncodeTime(4, 45, 45, 7);
  Memo1.Lines.Add(TimeToStr(MyTime));
  Memo1.Lines.Add(ExpandFileName('test.exe'));
end;

procedure TForm3.Button6Click(Sender: TObject);
var
  str: string;
  strList: TStrings;
  Time: Integer;
  date: TDateTime;
begin
  Memo1.Lines.Add(ExtractFileDrive(Application.ExeName));
  Memo1.Lines.Add(ExtractFileDrive('text.doc'));
  // strList := TStrings.Create;
  // strList.Add('http://bbs.csdn.net/topics/335676');
  // procedure ExtractHTTPFields(Separators, WhiteSpace: TSysCharSet; Content: PChar;Strings: TStrings; StripQuotes: Boolean = False);
  // ExtractHTTPFields(['.'],['/'],PChar('http://bbs.csdn.net/topics/335676'),strList);
  // ExtractHTTPFields(['.'], ['/'], PChar('http://bbs.csdn.net/topics/335676'), strList, True);
  // Memo1.Lines.Add(strList.Text);
  str := ExtractRelativePath('e:\delphi_workspace\', Application.ExeName);
  // 获取文件日期时间
  Memo1.Lines.Add(str);
  Time := FileAge('d:\test.doc');
  date := FileDateToDateTime(Time);
  Memo1.Lines.Add(DateToStr(date) + ' ' + TimeToStr(date));
  Memo1.Lines.Add(FormatDateTime('时间:dddd yyyy mmmm d号' + ' hh:mm:ss AM/PM',
      StrToDateTime('2013/10/5 10:30:33:55')));
end;

procedure TForm3.Button7Click(Sender: TObject);
var
  InputString, NewString: string;
  ClickedOK, ret: Boolean;
  Yr, Mnth, day: Word;
begin

  DecodeDate(date, Yr, Mnth, day);
  ret := IsLeapYear(Yr);
  if ret then
    ShowMessage('是闰年')
  else
    ShowMessage('不是闰年');

  InputString := InputBox('Input Box', 'Prompt', 'default string');
  ShowMessage(InputString);
  NewString := 'hehe';
  ClickedOK := InputQuery('Input Box', 'Prompt', NewString);
  If ClickedOK then
    ShowMessage(NewString);

end;

procedure TForm3.Button8Click(Sender: TObject);
var
  ret:Integer;
begin
  MessageDlgPos('Are you there?' ,mtConfirmation,mbYesNoCancel,100,200,200);
  MessageDlg('Exiting the Object Pascal application.',mtInformation,[mbOk],0);
  Randomize;
  ret:=Random(10);
  ShowMessage(IntToStr(ret));
end;

end.

你可能感兴趣的:(delphi API使用例子,日期时间等)