如何用DELPHI设置操作系统日期格式?(100分)

  • 主题发起人 主题发起人 kuikui
  • 开始时间 开始时间
K

kuikui

Unregistered / Unconfirmed
GUEST, unregistred user!
比如“99-9-1”设置为“1999/09/01”,好象没有这样的API函数。你碰到过这样的问题吗?
 
FormatDateTime格式化好吗?
 
use setsystemtime<br>The SetSystemTime function sets the current system time and date. The system time is expressed in Coordinated Universal Time (UTC). <br><br>BOOL SetSystemTime(<br><br>&nbsp; &nbsp; CONST SYSTEMTIME *lpSystemTime // address of system time to set <br>&nbsp; &nbsp;); <br>&nbsp;<br><br>Parameters<br><br>lpSystemTime<br><br>Points to a SYSTEMTIME structure that contains the current system date and time. <br>The wDayOfWeek member of the SYSTEMTIME structure is ignored. <br><br>&nbsp;<br><br>Return Values<br><br>If the function succeeds, the return value is nonzero.<br>If the function fails, the return value is zero. To get extended error information, call GetLastError. <br><br>Remarks<br><br>Windows NT: The SetSystemTime function fails if the calling process does not have the SE_SYSTEMTIME_NAME privilege. This privilege is disabled by default. Use the AdjustTokenPrivileges function to enable this privilege and again to disable it after the time has been set. For more information about security privileges, see Privileges. <br>Windows 95: Security privileges are not supported or required.<br><br>See Also<br><br>AdjustTokenPrivileges, GetSystemTime, SetSystemTimeAdjustment, SYSTEMTIME, SystemTimeToTzSpecificLocalTime
 
方法一。ShortDateFormat:='yyyy/mm/dd';这个只会修改当前进程的日期格式<br>方法二。修改注册表,HKEY_USERS/.DEFAULT/Control panel/International/下,<br>&nbsp; &nbsp; &nbsp; &nbsp; 有一个sShortDate,把它改为你想要的合法的格式,就可以了
 
理解错了。抱歉。关注继续
 
To:Nizvoo<br>&nbsp; 不对吧?我需要设置日期格式呀!<br><br>SYSTEMTIME structure 如下:<br>typedef struct _SYSTEMTIME { &nbsp;// st &nbsp;<br>&nbsp; &nbsp; WORD wYear; <br>&nbsp; &nbsp; WORD wMonth; <br>&nbsp; &nbsp; WORD wDayOfWeek; <br>&nbsp; &nbsp; WORD wDay; <br>&nbsp; &nbsp; WORD wHour; <br>&nbsp; &nbsp; WORD wMinute; <br>&nbsp; &nbsp; WORD wSecond; <br>&nbsp; &nbsp; WORD wMilliseconds; <br>} SYSTEMTIME; <br>&nbsp;
 
你到底是要修改win32的时间样式还是咋的?
 
&nbsp;SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDATE, 'YYYY/MM/DD');<br>&nbsp; SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0);<br>
 
to svw0506:<br>&nbsp; 按你的做法,也没有改变呀!
 
To:Nizvoo<br><br>是呀!
 
你重启动一下。<br>我手工变更注册表,发现没变重启后变了。<br>我根本先不写程序。我再再试
 
procedure TMainFrm.FormCreate(Sender: TObject);<br>begin<br>&nbsp; DateSeparator := '-';<br>&nbsp; ShortDateFormat := 'yyyy/mm/dd';<br>end;
 
format(date,'yyyy-mm-dd')
 
你还取的时候改变吧。我搞不定啊。。。。向上向。
 
我经常用以下代码:<br>&nbsp; DateSeparator := '-';<br>&nbsp; TimeSeparator := ':';<br>&nbsp; ShortDateFormat := 'yyyy-mm-dd';<br>&nbsp; LongDateFormat := 'yyyy"年"mm"月"dd"日"';<br>&nbsp; LongTimeFormat := 'hh:mm:ss';<br>&nbsp; ShortTimeFormat := 'hh:mm';<br>挺好用的。<br>你可以试试。
 
To:HHSH<br>&nbsp; 就这样就可以拉?不要说一半呀。。<br>
 
To: all<br>我弄出来拉,以下程序运行是可以的。受svw0506(但你的不完整,20分)的启发,谢谢大家!<br>var<br>&nbsp; DefLCID: LCID;<br>&nbsp; Buffer: array[0..255] of char;<br>begin<br>&nbsp; Application.UpdateFormatSettings := True;<br><br>&nbsp; StrPCopy(Buffer,'yyyy/MM/dd');<br>&nbsp; DefLCID := GetThreadLocale;<br>&nbsp; Result := False;<br>&nbsp; if SetLocaleInfo(DefLCID,LOCALE_SSHORTDATE,Buffer) then begin<br>&nbsp; &nbsp; ShortDateFormat := Buffer;<br>&nbsp; &nbsp; Result := True;<br>&nbsp; end;<br>&nbsp; Application.UpdateFormatSettings := False;<br>end;<br>
 
To: all<br>我弄出来拉,以下程序运行是可以的。受svw0506(但你的不完整,20分)的启发,谢谢大家!<br>
 
在控制面板-&gt;区域设置-&gt;把日期设置成你要的 yyyy/mm/dd 形式就行了<br>你在输入yyyy/mm/dd时,数据库也支持的
 
当主窗体显示时设枝<br>ShortDateFormat := 'yyyy/mm/dd';
 
后退
顶部