LOCALE_SPOSITIVESIGN LOCALE_ITIME LOCALE_SSHORTDATE LOCALE_S1159 LOCALE_STHOUSAND LOCALE_S2359 LOCALE_STIME LOCALE_SCURRENCY LOCALE_STIMEFORMAT lpLCData:需要设定的信息的存放地址; 与起对应的函数为 int GetLocaleInfo( LCID Locale, // locale identifier LCTYPE LCType, // type of information LPTSTR lpLCData, // address of buffer for information int cchData // size of buffer ); 主要用于取得当前系统的区域设置,各个参数和使用过程不再一一说明。 3 使用举例 //取得当前系统的短日期格式; function Tfrmmain.GetsysDateFormat: string; var sgs:string; begin setlength(sgs,12); GetLocaleInfo(LOCALE_SYSTEM_DEFAULT,LOCALE_SSHORTDATE ,PChar(sgs),12); result:=string(pchar(sgs)); end; //设定系日期格式; procedure Tfrmmain.SetSysDateFormat(s: string); begin SetLocaleInfo(LOCALE_SYSTEM_DEFAULT,LOCALE_SSHORTDATE,PChar(s)); end;
LOCALE_SPOSITIVESIGN
LOCALE_ITIME LOCALE_SSHORTDATE
LOCALE_S1159 LOCALE_STHOUSAND
LOCALE_S2359 LOCALE_STIME
LOCALE_SCURRENCY LOCALE_STIMEFORMAT
lpLCData:需要设定的信息的存放地址; 与起对应的函数为 int GetLocaleInfo( LCID Locale, // locale identifier
LCTYPE LCType, // type of information
LPTSTR lpLCData, // address of buffer for information
int cchData // size of buffer
);
主要用于取得当前系统的区域设置,各个参数和使用过程不再一一说明。 3 使用举例 //取得当前系统的短日期格式;
function Tfrmmain.GetsysDateFormat: string;
var
sgs:string;
begin
setlength(sgs,12);
GetLocaleInfo(LOCALE_SYSTEM_DEFAULT,LOCALE_SSHORTDATE ,PChar(sgs),12);
result:=string(pchar(sgs));
end; //设定系日期格式;
procedure Tfrmmain.SetSysDateFormat(s: string);
begin
SetLocaleInfo(LOCALE_SYSTEM_DEFAULT,LOCALE_SSHORTDATE,PChar(s));
end;
var
registry1:Tregistry;
应用程序启动时更改设置:
registry1:=tregistry.Create;
registry1.RootKey:=HKEY_CURRENT_USER;
registry1.OpenKey('Control Panel\International',true);
registry1.writestring('sShortDate','yyyy-MM-dd');
registry1.WriteString('sDate','-');
registry1.CloseKey;
registry1.Free;
DateSeparator = '-';
ShortDateFormat = 'yyyy-mm-dd';这样,你在程序中用到的日期格式就始终是 yyyy-mm-dd 了,就不用考虑系统设置的日期格式。
我来献丑了
打开->控制面板->区域选项->日期->日期格式-> 设为yy-M-d ->确定/应用OK搞定