Delphi两则:1、PDT时间转北京时间,2、条件编译

来源:互联网 发布:linux服务器防火墙设置 编辑:程序博客网 时间:2024/06/13 12:26
1、PDT时间转北京时间
   做了个小东西,时间是PDT,而且月份也是英文的。写了个小函数,有用得着的直接copy去:) 
有更好的实现方法,请回复。 
  1. uses DateUtils;
  2. function ConvertPDTDateTime(Str: string): TDateTime;
  3. const
  4.   EngMonthName: array[1..12of string = ('Jan''Feb''Mar''Apr''May''Jun',
  5.                                  'Jul''Aug''Sep''Oct''Nov''Dec');
  6. var
  7.   I: Integer;
  8.   fs: TFormatSettings;
  9. begin
  10.   fs.ShortDateFormat := 'mm-dd-yy';
  11.   fs.LongDateFormat := 'mm-dd-yyyyy';
  12.   fs.DateSeparator := '-';
  13.   fs.TimeSeparator := ':';
  14.   fs.LongTimeFormat := 'hh:nn:ss';
  15.   fs.ShortTimeFormat := 'hh:nn:ss';
  16.   fs.TwoDigitYearCenturyWindow := 50;
  17.   for I := 1 to 12 do
  18.   begin
  19.     Str := StringReplace(Str, EngMonthName[I], IntToStr(I), [rfIgnoreCase]);
  20.   end;
  21.   Result := StrToDateTime(Str, fs);
  22.   //PDT是Pacific Daylight Time的简称,意思是太平洋夏令时
  23.   //指的是美国西部时间
  24.   //-8区 和北京平时差16小时 4-10月夏令时差15小时
  25.   if Pos('PDT', Str) > 0 then
  26.   begin
  27.     if MonthOf(Result) in [4..10then
  28.       Result := IncHour(Result, 15)
  29.     else
  30.       Result := IncHour(Result, 16);
  31.   end;
  32. end;

调用方法:ConvertPDTDateTime('Oct-21-08 12:01:10 PDT') 

2、关于条件编译: 
如果你希望使用命令行dcc32.exe编译工程,请cd到dpr所在目录,否则条件变量可能无法生效(至少我{$I xxx.inc}进来的无效。 

原创粉丝点击