怎么样用delphi 写程序修改系统日期
解决方案 »
- 简单的sql语句
- 一个简单的 String语句如何实现!
- 网站更新,欢迎各位D类参观
- 在2000注销后未登陆的时候,希望一个程序在运行怎么设置?急!!!!!!!!!!!
- 神奇的问题????
- 求一套视频实时监控系统的解决方案。高分!!!
- 菜鸟问题,早回答早给分!
- 在ADO中结果集中,如何只从服务器上更新一条记录而不涉及到其他的记录?
- 一个多页面浏览器的测试版,请大家帮忙测试,谢谢!
- 谁有可以上大富翁的代理服务器的地址?如可用,给150分!看一看我的提问,从不会"拖分"的 : )
- fastreport 传递变量值为汉字出错
- 如何DELPHI实现TXT到EXCEL互相转化?各位大虾一人给点思路,进来的都给分分~~
var
str: string;beginstr := RadioGroup1.Items.Strings[RadioGroup1.ItemIndex];if SetLocaleInfoa(LOCALE_SYSTEM_DEFAULT, LOCALE_SSHORTDATE , PChar(str)) thenbeginshowmessage('short OK!');thenSendMessageA(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0);end;end;为了方便测试我用了radioGroup,items 内容如下yy-d-md-yy-mm-d-yyyy-m-dyyyy-m-dyyyy-d-m 传进参数必须 null-terminate 字符串指针。我用 pchar ,而且字符串格式只能写成这样 'm-d'而不是'mm-dd'('yyyy'可以用),不然改不了另外delphi 函数 DateTostr,DateTimeTostr,都调用短格式。长格式很灵活。随便改.RadioGroup Items 如下yyy'年'dd'日'-mmd-yyyy-mmmm-dd-yyyyyyyy-mm-dd代码如下varstr: string;beginstr := RadioGroup2.Items.Strings[RadioGroup2.ItemIndex];if SetLocaleInfoa(LOCALE_SYSTEM_DEFAULT, LOCALE_SLONGDATE , PChar(str)) thenbeginshowmessage('Loan OK!');SendMessageA(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0);end;end;//你应该搜索一下,有着方面的讨论。
SetLocaleInfo(LOCALE_SYSTEM_DEFAULT,LOCALE_SSHORTDATE,'yyyy-MM-dd');
{ (c) by UNDO }
var
tSetDati: TDateTime;
vDatiBias: Variant;
tTZI: TTimeZoneInformation;
tST: TSystemTime;
begin
GetTimeZoneInformation(tTZI);
vDatiBias := tTZI.Bias / 1440;
tSetDati := DateTime + vDatiBias;
with tST do
begin
wYear := StrToInt(FormatDateTime('yyyy', tSetDati));
wMonth := StrToInt(FormatDateTime('mm', tSetDati));
wDay := StrToInt(FormatDateTime('dd', tSetDati));
wHour := StrToInt(FormatDateTime('hh', tSetDati));
wMinute := StrToInt(FormatDateTime('nn', tSetDati));
wSecond := StrToInt(FormatDateTime('ss', tSetDati));
wMilliseconds := 0;
end;
Result := Windows.SetSystemTime(tST);
end;
var
myst:TsystemTime;
begin
with MYST do
begin
wYear:=strtoint(edit1.Text);
wMOnth:=strtoint(edit2.text);
wDay:=strtoint(edit3.Text);
wHour:=strtoint(edit4.Text);
wMinute:=strtoint(edit5.Text);
wSecond:=strtoint(edit6.Text);
end;
setsystemtime(myST);end;
VAR
MYT:_SYSTEMTIME;
begin
MYT.wYear:=2001;
MYT.wMonth:=12;
MYT.wDay:=1;
MYT.wHour:=12;
MYT.wMinute:=2;
MYT.wSecond:=3;
SetLocalTime(MYT);
end;
var
MYT:Tsystemtime;
begin
MYT.wYear:=2001;
MYT.wMonth:=09;
MYT.wDay:=01;
SetlocalTime(MYT);
end;
我的程序是这样的,可是能够编译成功,但时间该不了是怎么回事?
------------------------------
设置系统时间在NT/xp中,设置系统时间可能需要特权的,下面的代码可以调整特权来设置时间,和调整关机权限类似。
http://www.chami.com/tips/delphi/120496D.htmlfunction SetPrivilege(
sPrivilegeName : string;
bEnabled : boolean )
: boolean;
var
TPPrev,
TP : TTokenPrivileges;
Token : THandle;
dwRetLen : DWord;
begin
Result := False; OpenProcessToken(
GetCurrentProcess,
TOKEN_ADJUST_PRIVILEGES
or TOKEN_QUERY,
@Token ); TP.PrivilegeCount := 1;
if( LookupPrivilegeValue(
Nil,
PChar( sPrivilegeName ),
TP.Privileges[ 0 ].LUID ) )then
begin
if( bEnabled )then
begin
TP.Privileges[ 0 ].Attributes :=
SE_PRIVILEGE_ENABLED;
end else
begin
TP.Privileges[ 0 ].Attributes :=
0;
end; dwRetLen := 0;
Result := AdjustTokenPrivileges(
Token,
False,
TP,
SizeOf( TPPrev ),
TPPrev,
dwRetLen );
end; CloseHandle( Token );
end;procedure ChangeSystemTime;
var
st : TSystemTime;
begin
if( SetPrivilege(
'SeSystemtimePrivilege',
True ) )then
begin
GetLocalTime( st ); //
// change time using st structure
// for example, to 10:30pm
//
st.wHour := 22;
st.wMinute := 30; SetLocalTime( st );
// or :
// SetSystemTime( st ); SetPrivilege(
'SeSystemtimePrivilege',
False );
end;
end;