Delphi의 시간 및 문자열 함수 코드 예

SysUtils.StrToDate();
SysUtils.StrToDateDef();
SysUtils.TryStrToDate();

SysUtils.StrToTime();
SysUtils.StrToTimeDef();
SysUtils.TryStrToTime();

SysUtils.StrToDateTime();
SysUtils.StrToDateTimeDef();
SysUtils.TryStrToDateTime();

SysUtils.DateToStr();
SysUtils.TimeToStr();
SysUtils.DateTimeToStr();
SysUtils.DateTimeToString();

SysUtils.FormatDateTime();
SysUtils.FormatDateTime();     :
 unit Unit1;
interface
uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs;

type
 TForm1 = class(TForm)
  procedure FormCreate(Sender: TObject);
 end;

var
 Form1: TForm1;

implementation

{$R *.dfm}

uses DateUtils;

procedure TForm1.FormCreate(Sender: TObject);
var
 d: TDateTime;
 str: string;
 fmt: TFormatSettings;
begin
 d := StrToDateTime('2009-5-21 11:22:33');

 str := DateTimeToStr(d);
 ShowMessage(str); // 2009-5-21 11:22:33

 GetLocaleFormatSettings(GetThreadLocale, fmt);
 fmt.DateSeparator := '/';
 fmt.TimeSeparator := '_';
 fmt.ShortDateFormat := 'dd/mm/yyyy';
 fmt.ShortTimeFormat := 'hh:mm:ss';
 str := DateTimeToStr(d, fmt);
 ShowMessage(str); // 21/05/2009 11_22_33

 DateTimeToString(str, 'yyyy   m   d   h   m   s  ', d);
 ShowMessage(str); //2009   5   21   11   22   33  
end;

end.

좋은 웹페이지 즐겨찾기