標籤:
問題現象:我想大家都遇到過在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電腦上的日期錯誤處理