关于 PostgreSQL 日期格式的区域设置混乱
我正在开发一个需要以下区域设置的应用程序(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)!
Check the image.
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
DateToStr
使用ShortDateFormat
作为输出格式。您没有从最初设置的MM/dd/yy
中更改它;您只更改了DateSeparator
。但我很困惑,为什么你想使用
(Fields(1).Text)
(是吗?用括号代替 Fields 下标的 [] ?)。如果数据库配置为使用
|
作为日期分隔符,因为它看起来来自您的屏幕图像,那么为什么要使用DateToStr
?看来.Text
正在以您想要获取的格式获取信息。DateToStr
usesShortDateFormat
as the output format. You didn't change that from theMM/dd/yy
set initially; you only changed theDateSeparator
.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 usingDateToStr
? It appears that.Text
is getting the information in the format you're looking to obtain.好的,我在一个网站上找到了
在此处输入链接说明
为了获得适当的格式,我所要做的就是将查询激发为
选择 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