본문 바로가기

카테고리 없음

[시스템] Time Zone 정보를 시분으로 읽어오기

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

const
  // 아래 상수는 windows.pas 에 선언되어 있지 않음
  TIME_ZONE_ID_UNKNOWN  = 0;
  TIME_ZONE_ID_STANDARD = 1;
  TIME_ZONE_ID_DAYLIGHT = 2;

var
  Form1: TForm1;

implementation
{$R *.DFM}

function FormatHourMin(TotalMins: LongInt): String;
var
  Hr, Min: LongInt;
  H: String[10];
  M: String[10];
  neg: boolean;
begin
  neg := totalmins < 0;
  if neg then
    totalmins := -1*TotalMins;
  Hr := TotalMins div 60;
  Min := TotalMins mod 60;
  Str(Hr:2, H);
  Str(Min:2, M);
  if H[1] = ' ' then
    H[1] := '0';
  if M[1] = ' ' then
    M[1] := '0';
  if neg then
    FormatHourMin := '-'+H+'시 '+M+'분'
  else
    FormatHourMin := H+'시 '+M+'분';
end;

function GetLocalTimeZoneOffSet: String;
var
  tz: TTimeZoneInformation;
begin
  result := '';

  case GetTimeZoneInformation(tz) of
    TIME_ZONE_ID_UNKNOWN:
       begin
        result := FormatHourMin(-1*tz.bias);
        if tz.bias = 0 then result := 'GMT'
       end;
    TIME_ZONE_ID_STANDARD:
       result := FormatHourMin(-1*tz.bias);
    TIME_ZONE_ID_DAYLIGHT:
       result := FormatHourMin(-1*(tz.bias+tz.standardbias+
                                   tz.daylightbias));
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  // 우리나라는 9시 0분 입니다
  ShowMessage(GetLocalTimeZoneOffSet);
end;

end.