分享

delphi中日期格式的设定

 独孤求财 2012-06-06

delphi中日期格式的设定

(2011-10-14 17:38:57)
 

  XP和Win7的日期格式在系统默认中并不一致,也许会对编程造成困扰,不是吗?

  设定系统日期的默认格式可以改变这一问题,可是这听起来并不完美。

  

  通过Forms.TApplication.UpdateFormatSettings设定可以很好的解决问题。这是Help里的描述:

Specifies whether format settings are updated automatically when the user alters the system configuration.

Use UpdateFormatSettings to control automatic updating of format settings. The default of true is set in the constructor. UpdateFormatSettings is checked when the application receives a WM_WININICHANGE message.

Using the default format settings is recommended. These settings are initialized to the Windows local settings. 

 

通过UpdateFormatSettings我们可以手动设定程序所要使用的日期时间格式,代码如下:

1
2
3
4
5
6
7
8
9
10
//锁定程序日期格式不受系统变化的影响
Application.UpdateFormatSettings := false;

//设定程序本身所使用的日期时间格式
LongDateFormat  := 'yyyy/MM/dd';
ShortDateFormat := 'yyyy/MM/dd';
LongTimeFormat  := 'hh:nn:ss';
ShortTimeFormat := 'hh:nn:ss';
DateSeparator := '/';
TimeSeparator := ':';

这样程序中使用的时间格式就不会再受时间变化影响。

以下的代码或许更全面:

procedure Tposmain.sys_format;

begin

 CurrencyString:='¥';    // 货币符号

 currencyformat:=0;    // 货币格式

 negcurrformat:=2;

 thousandseparator:=',';  // 货币千分位数分隔符号

 decimalseparator:='.';   // 小数点符号

 currencydecimals:=2;  // 货币小数位数

 dateseparator:='-';  // 日期分隔符

 shortdateformat:='yyyy-mm-dd'; // 短日期格式

 longdateformat:='yyyy-mm-dd'; // 长日期格式

 timeSeparator:=':'; // 时间 分隔符

 shortTimeFormat:='hh:mm:ss'; // 短时间格式

 longtimeformat:='hh:mm:ss'; //长时间格式

//  TimeAMString:='AM'; // 上午

//  TimePMString:='PM'; // 下午

 application.UpdateFormatSettings:=false;

end;

本文摘编自网络

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多