如何在 Delphi 5 中获得正确的 DateSeparator?

How to get correct DateSeparator in Delphi 5?

当系统区域设置为 Cenz Republic 时,我正在尝试获取正确的 DateSeparator。当前日期的格式为 9.3.2017,但 DateSeparator 始终为 '/' 而不是 '.'。我该怎么做才能获得正确的日期分隔符?

关于日期表示,有几个单独的全局变量会影响输出。你提到了其中两个:

`DateSeparator: Char;` (initialized from registry with reference `LOCALE_SDATE`)
`ShortDateFormat: string;` (initialized from registry with reference `LOCALE_SSHORTDATE`)

您可以在文档或单元 SysUtils 中的代码中看到的其他内容从第 490 行开始(在 Delphi 7 中,在 Delphi 5 中可能有所不同)。 =16=]

由于 DateSeparatorShortDateFormat 是不同的变量,您可能会看到根据您的语言环境正确显示的日期,而 DateSeparator return 是一个错误字符.

要纠正,您可以在自己的代码中将正确的字符分配给 DateSeparator,但请注意,如果您使用的是第 3 方库,它们可能也想更改它。