打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
delphi中日期格式的设定

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;

本文摘编自网络

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Oracle PL/SQL开发基础(第二十二弹:类型转换函数)
日期格式化与字符串转换成时间(C#.NET) — Windows Live
c#-检索当前的Outlook约会
Excel用函数把时间戳格式和日期格式相互转换
Oracle日期格式的转化技巧
MySql中获取当前系统当前时间
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服