GMT 시간 형식을 TDateTime(Delphi)으로 변환

18953 단어 DateTime
 1 //GMT   TDateTime  2 //   3 function GMT2DateTime(const pSour:PAnsiChar):TDateTime;  4 

 5   function GetMonthDig(const Value:PAnsiChar):Integer;  6   const

 7     MonthDig:array[1..12] of PAnsiChar =

 8  (  9      'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'

10  ); 11   var

12  Index:Integer; 13   begin

14     Result := 0; 15     for Index := 1 to 12 do

16     begin

17       if AnsiStrIComp(Value,MonthDig[Index]) = 0 then

18       begin

19         Result := Index; 20  Break; 21       end; 22     end; 23   end; 24 

25 var

26   A:array[1..32] of Ansichar; 27  P1,P2:PAnsiChar; 28  Len:Integer; 29  wDay,wMonth,wYear,wHour,wMinute,wSec:Word; 30  D:TDateTime; 31 begin

32  //P1 := ' Mon, 12 Aug 2013 16:20:35 GMT'; 33   Result := 0; 34   P1 := pSour; 35   P2 := @A[1]; 36   Len := 31; 37   while((Len > 0) and (P1^ <>#0)) do

38   begin

39     P2^ := P1^; 40  Inc(P1); 41  Inc(p2); 42  Dec(Len); 43   end; 44   P2^ := #0; 45 

46   P1 := @A[1]; 47   while((P1^<>',') and (P1^ <>#0)) do Inc(P1);Inc(p1); 48 

49   //12

50   while((P1^ <> #32) and (P1^ <>#0)) do Inc(P1);Inc(p1);P2 := P1; 51   while((P2^ <> #32) and (P2^ <>#0)) do Inc(P2); P2^ := #0; 52   wDay := StrToIntDef(P1,-1); 53 

54   //Aug 55   P1 := P2; Inc(P1);P2 := P1; 56   while( (P2^<>#32) and (P2^ <>#0)) do Inc(P2);P2^ := #0; 57   wMonth := GetMonthDig(P1); 58   if wMonth = 0 then

59  Exit; 60 

61   //2013

62   P1 := P2; Inc(P1);P2 := P1; 63   while( (P2^<>#32) and (P2^ <>#0) ) do Inc(P2);P2^ := #0; 64   wYear := StrToIntDef(P1,-1); 65   if wYear = 0 then

66  Exit; 67 

68   //Hour 69   P1 := P2; Inc(P1);P2 := P1; 70   while((P2^<>':') and (P2^ <>#0)) do Inc(P2);P2^ := #0; 71   wHour := StrToIntDef(P1,-1); 72   if wHour < 0 then

73  Exit; 74 

75   //Min 76   P1 := P2; Inc(P1);P2 := P1; 77   while((P2^<>':') and (P2^ <>#0)) do Inc(P2);P2^ := #0; 78   wMinute := StrToIntDef(P1,-1); 79   if wMinute < 0 then

80  Exit; 81 

82   //Sec 83   P1 := P2; Inc(P1);P2 := P1; 84   while((P2^<>#32) and (P2^ <>#0)) do Inc(P2);P2^ := #0; 85   wSec := StrToIntDef(P1,-1); 86   if wSec < 0 then

87  Exit; 88 

89   Result := EnCodeDateTime(wYear,wMonth,wDay,wHour,wMinute,wSec,0); 90 

91 end;

 
TDateTime을 GMT 시간 형식으로 변환
 1 function DateTimeToGMT(const ADate:TDateTime):string;

 2 const

 3   WEEK:array[1..7] of PChar = ('Sun','Mon','Tues','Wed','Thur','Fri','Sat');

 4   MonthDig:array[1..12] of PChar =

 5     ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');

 6 

 7 var

 8   wWeek,wYear,wMonth,wDay,wHour,wMin,wSec,wMilliSec:Word;

 9   A:array[1..32] of AnsiChar;

10   P1,P2:PAnsiChar;

11   sWeek,sMonth:string;

12 begin

13   DecodeDateTime(ADate,wYear,wMonth,wDay,wHour,wMin,wSec,wMilliSec);

14   wWeek := DayOfWeek(ADate);

15   sWeek  := WEEK[wWeek];

16   sMonth := MonthDig[wMonth];

17   Result := Format(' %s, %d %s %d %d:%d:%d GMT',[sWeek,wDay,sMonth,wYear,wHour,wMin,wSec]);

18 end;

 
 

좋은 웹페이지 즐겨찾기