問題-[Delphi7]程式在WIN7電腦上的日期錯誤處理

來源:互聯網
上載者:User

標籤:

問題現象:我想大家都遇到過在XP上沒有問題的日期格式,到了WIN7之後就不行了。

問題原因:因為在WIN7中增加了新的日期格式,但是老的DELPHI未處理(如果我說錯了,希望高人指點)。

問題處理:

function StrToDateWin7(DateStr: string): TDateTime;
var
  T: TDateTime;
  Fs: TFormatSettings;
begin
  try
    Fs.ShortDateFormat := ‘yyyy-mm-dd‘;
    Fs.DateSeparator := ‘-‘;
    T := StrToDate(DateStr, Fs);
  except
    T := StrToDate(‘1899-01-01‘, Fs);
  end;
  Result := T;
end;

PS:

DateSeparator :Char

日期分隔符號,用於分隔年月日 
TimeSeparator :Char 
時間分隔字元,用於分隔小時,分鐘,秒 
ShortDateFormat:String 
地區設定中短日期格式的定義。 
LongDateFormat :String 
地區設定中長日期格式的定義。 
ShortTimeFormat:String 
地區設定中短時間格式的定義。 
LongTimeFormat :String 
地區設定中長時間格式的定義。 
TimeAMString :String 
用來表示上午的字串 
TimePMString :String 
用來表示下午的字串 
ShortMonthNames:array[1..12] of String; 
用於縮減表示月份名稱的數組,就是在使用FormatDateTime時顯示的mmm標識的字串 
LongMonthNames:array[1..12] of String; 
用於完整表示月份名稱的數組,就是在使用FormatDateTime時顯示的mmmm標識的字串 
ShortDayNames :array[1..7] of String; 
用於縮減表示星期名稱的數組,就是在使用FormatDateTime時顯示的ddd標識的字串 
LongDayNames :array[1..7] of String; 
用於完整表示星期名稱的數組,就是在使用FormatDateTime時顯示的ddd標識的字串 
TwoDigitYearCenturyWindow:Word = 50; 
在使用兩位年份時的起始年份。

問題-[Delphi7]程式在WIN7電腦上的日期錯誤處理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.