Delphi兩則:1、PDT時間轉北京時間,2、條件編譯

來源:互聯網
上載者:User
1、PDT時間轉北京時間
   做了個小東西,時間是PDT,而且月份也是英文的。寫了個小函數,有用得著的直接copy去:) 
有更好的實現方法,請回複。 
  1. uses DateUtils;
  2. function ConvertPDTDateTime(Str: string): TDateTime;
  3. const
  4.   EngMonthName: array[1..12] of 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..10] then
  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}進來的無效。 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.