unit WinForm1;

interface

uses
  System.Drawing, System.Collections, System.ComponentModel,
  System.Windows.Forms, System.Data, System.Globalization;

type
  TWinForm1 = class(System.Windows.Forms.Form)
  {$REGION 'Designer Managed Code'}
  strict private
    /// <summary>
    /// Required designer variable.
    /// </summary>
    Components: System.ComponentModel.Container;
    Button1: System.Windows.Forms.Button;
    Button2: System.Windows.Forms.Button;
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    procedure InitializeComponent;
    procedure TWinForm1_Load(sender: System.Object; e: System.EventArgs);
    procedure Button1_Click(sender: System.Object; e: System.EventArgs);
    procedure Button2_Click(sender: System.Object; e: System.EventArgs);
  {$ENDREGION}
  strict protected
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    procedure Dispose(Disposing: Boolean); override;
  private
    { Private Declarations }
  public
    constructor Create;
  end;

  [assembly: RuntimeRequiredAttribute(TypeOf(TWinForm1))]

implementation

{$AUTOBOX ON}

{$REGION 'Windows Form Designer generated code'}
/// <summary>
/// Required method for Designer support -- do not modify
/// the contents of this method with the code editor.
/// </summary>
procedure TWinForm1.InitializeComponent;
begin
  Self.Button1 := System.Windows.Forms.Button.Create;
  Self.Button2 := System.Windows.Forms.Button.Create;
  Self.SuspendLayout;
  // 
  // Button1
  // 
  Self.Button1.Location := System.Drawing.Point.Create(10, 9);
  Self.Button1.Name := 'Button1';
  Self.Button1.Size := System.Drawing.Size.Create(96, 27);
  Self.Button1.TabIndex := 0;
  Self.Button1.Text := 'Czas';
  Include(Self.Button1.Click, Self.Button1_Click);
  // 
  // Button2
  // 
  Self.Button2.Location := System.Drawing.Point.Create(120, 8);
  Self.Button2.Name := 'Button2';
  Self.Button2.Size := System.Drawing.Size.Create(96, 27);
  Self.Button2.TabIndex := 1;
  Self.Button2.Text := 'Data';
  Include(Self.Button2.Click, Self.Button2_Click);
  // 
  // TWinForm1
  // 
  Self.AutoScale := False;
  Self.AutoScaleBaseSize := System.Drawing.Size.Create(6, 15);
  Self.ClientSize := System.Drawing.Size.Create(224, 43);
  Self.Controls.Add(Self.Button2);
  Self.Controls.Add(Self.Button1);
  Self.Name := 'TWinForm1';
  Self.Text := 'Czas i data (Windows Forms)';
  Include(Self.Load, Self.TWinForm1_Load);
  Self.ResumeLayout(False);
end;
{$ENDREGION}

procedure TWinForm1.Dispose(Disposing: Boolean);
begin
  if Disposing then
  begin
    if Components <> nil then
      Components.Dispose();
  end;
  inherited Dispose(Disposing);
end;

constructor TWinForm1.Create;
begin
  inherited Create;
  //
  // Required for Windows Form Designer support
  //
  InitializeComponent;
  //
  // TODO: Add any constructor code after InitializeComponent call
  //
end;

procedure TWinForm1.Button2_Click(sender: System.Object; e: System.EventArgs);
var format: System.Globalization.DateTimeFormatInfo;
     tmp: System.Globalization.CultureInfo;
     w: string;
     dt: Datetime;
begin
tmp:=System.Globalization.CultureInfo.InstalledUICulture;
format:=System.Globalization.DateTimeFormatInfo(tmp.DateTimeFormat.Clone);
dt:=DateTime.Now;
w:='Przykłady formatowania daty:'+#13+#13;
format.DateSeparator:='-';
format.ShortDatePattern:='dd-mm-yyyy';
w:=w+'Format: '+format.ShortDatePattern+', data: '+dt.ToString(format.ShortDatePattern,format)+#13;

format.DateSeparator:='/';
format.ShortDatePattern:='dd/mm/yyyy';
w:=w+'Format: '+format.ShortDatePattern+', data: '+dt.ToString(format.ShortDatePattern,format)+#13;

format.DateSeparator:='/';
format.ShortDatePattern:='dd/mm/yyyy';
w:=w+'Format: '+format.ShortDatePattern+', data: '+dt.ToString(format.ShortDatePattern,format)+#13;

format.DateSeparator:='-';
format.ShortDatePattern:='yyyy-mm-dd';
w:=w+'Format: '+format.ShortDatePattern+', data: '+dt.ToString(format.ShortDatePattern,format)+#13;

format.ShortDatePattern:='yyyy';
w:=w+'Format: '+format.ShortDatePattern+', data: '+dt.ToString(format.ShortDatePattern,format)+#13;

format.ShortDatePattern:='yy';
w:=w+'Format: '+format.ShortDatePattern+', data: '+dt.ToString(format.ShortDatePattern,format)+#13;

format.DateSeparator:='-';
format.ShortDatePattern:='d-m-y';
w:=w+'Format: '+format.ShortDatePattern+', data: '+dt.ToString(format.ShortDatePattern,format)+#13;


format.ShortDatePattern:='d MMMM yyyy';
w:=w+'Format: '+format.ShortDatePattern+', data: '+dt.ToString(format.ShortDatePattern,format)+#13;

format.ShortDatePattern:='dddd';
w:=w+'Format: '+format.ShortDatePattern+', data: '+dt.ToString(format.ShortDatePattern,format)+#13;

format.ShortDatePattern:='d MMMM yyyy (dddd)';
w:=w+'Format: '+format.ShortDatePattern+', data: '+dt.ToString(format.ShortDatePattern,format)+#13;
MessageBox.Show(w);

end;

procedure TWinForm1.Button1_Click(sender: System.Object; e: System.EventArgs);
var format: System.Globalization.DateTimeFormatInfo;
     tmp: System.Globalization.CultureInfo;
     w: string;
     dt: System.DateTime;
     i:integer;
begin
tmp:=System.Globalization.CultureInfo.InstalledUICulture;
format:=System.Globalization.DateTimeFormatInfo(tmp.DateTimeFormat.Clone);
dt:=DateTime.Now;
w:='Przykłady formatowania czasu:'+#13+#13;

format.LongTimePattern:='t';
w:=w+'Format: '+format.LongTimePattern+', czas: '+dt.ToString(format.LongTimePattern,format)+#13;

format.LongTimePattern:='hh:mm';
w:=w+'Format: '+format.LongTimePattern+', czas: '+dt.ToString(format.LongTimePattern,format)+#13;

format.LongTimePattern:='h:mm';
w:=w+'Format: '+format.LongTimePattern+', czas: '+dt.ToString(format.LongTimePattern,format)+#13;

format.LongTimePattern:='hh:mm:ss.fff';
w:=w+'Format: '+format.LongTimePattern+', czas: '+dt.ToString(format.LongTimePattern,format)+#13;

format.LongTimePattern:='hh:mm:ssfff';
w:=w+'Format: '+format.LongTimePattern+', czas: '+dt.ToString(format.LongTimePattern,format)+#13;

format.LongTimePattern:='hh\\mm\\ss';
w:=w+'Format: '+format.LongTimePattern+', czas: '+dt.ToString(format.LongTimePattern,format)+#13;

format.LongTimePattern:='HH:mm:ss';
w:=w+'Format: '+format.LongTimePattern+', czas: '+dt.ToString(format.LongTimePattern,format)+#13;

format.LongTimePattern:='HH:mm zzz';
w:=w+'Format: '+format.LongTimePattern+', czas: '+dt.ToString(format.LongTimePattern,format)+#13;
DateTime.DaysInMonth(1978,12);
format.LongTimePattern:='\k\o\m\e\n\t\a\r\z hh:mm:ss ';
w:=w+'Format: '+format.LongTimePattern+', czas: '+dt.ToString(format.LongTimePattern,format)+#13;
MessageBox.Show(w);
end;

procedure TWinForm1.TWinForm1_Load(sender: System.Object; e: System.EventArgs);

begin

end;

end.
