• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

GMT时间格式转换到TDateTime(Delphi)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
 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;

 

 

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Delphi中的引号发布时间:2022-07-18
下一篇:
Delphi的编译指令(1):$DEFINE、$UNDEF、$IFDEF、$ELSE、$ENDIF发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap