如何在Delphi中获取本地化的日期名称?

Rod*_*ddy 8 delphi dayofweek

我正在使用标准Delphi常量DayMonday等,我想将它们转换为本地化字符串(例如"Lundi").是否有简单的RTL或VCL调用?

Too*_*the 7

您可以通过以下方式获取不同的区域设置

var
  fs : TFormatSettings;
  x  : string;
begin
  GetLocaleFormatSettings(GetThreadlocale, fs);
  x:= FormatDateTime('%mmmm', Now, fs);
  // etc..
end;
Run Code Online (Sandbox Code Playgroud)

GetThreadLocale给出了当前的LCID,但您可以自己使用其他数字.

TFormatSettings记录:

TFormatSettings = record
  CurrencyFormat: Byte;
  NegCurrFormat: Byte;
  ThousandSeparator: Char;
  DecimalSeparator: Char;
  CurrencyDecimals: Byte;
  DateSeparator: Char;
  TimeSeparator: Char;
  ListSeparator: Char;
  CurrencyString: string;
  ShortDateFormat: string;
  LongDateFormat: string;
  TimeAMString: string;
  TimePMString: string;
  ShortTimeFormat: string;
  LongTimeFormat: string;
  ShortMonthNames: array[1..12] of string;
  LongMonthNames: array[1..12] of string;
  ShortDayNames: array[1..7] of string;
  LongDayNames: array[1..7] of string;
  TwoDigitYearCenturyWindow: Word;
end;
Run Code Online (Sandbox Code Playgroud)

有关完整列表,另请参见http://www.microsoft.com/globaldev/reference/lcid-all.mspx.

您甚至可以自己更改格式设置以创建非常精美的结果.