关于 PostgreSQL 日期格式的区域设置混乱

发布于 2024-12-20 02:53:44 字数 1173 浏览 4 评论 0原文

我正在开发一个需要以下区域设置的应用程序(Delphi 7 和 PostgreSQL 9.0):

   1. DateSeparator:='/';
   2. TimeSeparator:=':';
   3. ThousandSeparator:=',';
   4. DecimalSeparator:='.';
   5. ShortDateFormat:='MM/dd/yy';
   6. ShortTimeFormat:='hh:mm:ss';

我只需要更改我的应用程序的区域设置,而不是系统范围的区域设置。

在表单的 OnCreate 中,我设置了上述分隔符,并且 我当前的系统分隔符是:(

   1. DateSeparator='|';
   2. TimeSeparator='|';
   3. ThousandSeparator='|';
   4. DecimalSeparator='|';

这是出于测试目的。)

现在在 Postgres 中,我有一个表,可以从中获取要在应用程序中显示的日期,但不知何故,日期分隔符似乎不起作用(如 label1 中所示)!

在此处输入图像描述

检查图像。

在此处输入图像描述

我触发查询以从表中获取日期

                    Label1.Caption:=(Fields(1).Text);
                    Label2.Caption:=datetostr(Fields(1).Data) ;

如果我将其视为,查询

 select min(dat), max(dat) from diary where survey in (2008401) and event not in ('E','C','R') and region=6100;

现在是相同的日期.data 的日期分隔符与 .text 的日期分隔符不同 为什么会发生这种情况?

为什么区域设置未应用于 label1.caption(如图所示)?

I'm working on an application that requires the following regional settings (Delphi 7 and PostgreSQL 9.0):

   1. DateSeparator:='/';
   2. TimeSeparator:=':';
   3. ThousandSeparator:=',';
   4. DecimalSeparator:='.';
   5. ShortDateFormat:='MM/dd/yy';
   6. ShortTimeFormat:='hh:mm:ss';

I need to change the regional setting only for my application and not system wide.

In OnCreate of the form I set the above separators, and
my current system separators are:

   1. DateSeparator='|';
   2. TimeSeparator='|';
   3. ThousandSeparator='|';
   4. DecimalSeparator='|';

(This is for the test purpose.)

Now in Postgres I have a table from where I get dates to display in my application but somehow the dateseparator doesn't seem to work (as seen in label1)!

enter image description here

Check the image.

enter image description here

I fire a query to get the dates from the table

                    Label1.Caption:=(Fields(1).Text);
                    Label2.Caption:=datetostr(Fields(1).Data) ;

The query is

 select min(dat), max(dat) from diary where survey in (2008401) and event not in ('E','C','R') and region=6100;

now the same date if I take as .data differ in the date separator from .text dateseparator
why this is happening?

Why are the regional settings not applied to label1.caption (as shown in the image)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

乖乖公主 2024-12-27 02:53:44

DateToStr 使用 ShortDateFormat 作为输出格式。您没有从最初设置的 MM/dd/yy 中更改它;您只更改了DateSeparator

但我很困惑,为什么你想使用 (Fields(1).Text) (是吗?用括号代替 Fields 下标的 [] ?)。

如果数据库配置为使用 | 作为日期分隔符,因为它看起来来自您的屏幕图像,那么为什么要使用 DateToStr?看来 .Text 正在以您想要获取的格式获取信息。

DateToStr uses ShortDateFormat as the output format. You didn't change that from the MM/dd/yy set initially; you only changed the DateSeparator.

I'm confused though, about why you'd want to use (Fields(1).Text) (is that right? Parentheses instead of [] for the Fields subscript?).

If the DB is configured to use | as the date separator, as it appears it is from your screen image, why are you using DateToStr? It appears that .Text is getting the information in the format you're looking to obtain.

叹梦 2024-12-27 02:53:44

好的,我在一个网站上找到了
在此处输入链接说明
为了获得适当的格式,我所要做的就是将查询激发为

选择 to_char(min(dat),'mm/dd/yy'), to_char(min(dat),'mm/dd/yy')
来自日记
其中调查 (2008401) 和
事件不在 ('E','C','R') 且区域=6100;

这给了我我想要的格式的正确结果

ok i found on one site
enter link description here
for getting the appropriate format all i had to do was get the fire the query as

select to_char(min(dat),'mm/dd/yy'), to_char(min(dat),'mm/dd/yy')
from diary
where survey in (2008401) and
event not in ('E','C','R') and region=6100;

This gave me the proper result in the format i wanted

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文