在 Asp.net c# 中设置 windows 时钟

Set windows clock in Asp.net c#

我需要在我的 Asp.net 网站中设置 windows 时钟(用 C# 编写)

我在 Whosebug 中找到了一个解决方案:

How do I set the Windows system clock to the correct local time using C#?

但是当我使用这个时,我给出了例外:

客户端没有所需的权限

我的应用程序轮询身份是:LocalSystem

不是"I need exact C# function for my problem"的问题,这是误导。这是一个安全问题。干扰时钟是不好的。无论如何,要解决此问题,您可以尝试 运行在管理员组成员的用户帐户下启用应用程序池并禁用 UAC。

您将无法更改远程客户端上的时钟。

...也不要 运行 杀毒软件!

哦,还有禁用系统设置的时钟同步。

<

div class="dp-highlighter"><div class="bar"><div class="tools">view plaincopy to clipboardprint?</div><div class="columns"><div>·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150</div></div></div>

    protected void Page_Load(object sender, EventArgs e)  
    {  
            lblTime.Text = DateTime.Now.ToString("hh:mm:ss");  

        }  
        protected void TimerTime_Tick(object sender, EventArgs e)  
        {  
            lblTime.Text = DateTime.Now.ToString("hh:mm:ss");  
        }  

    <asp:ScriptManager ID="ScriptManager1" runat="server">  
            </asp:ScriptManager>  
            <asp:Timer ID="TimerTime" runat="server" Interval="1000">  
            </asp:Timer>  
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">  
            <ContentTemplate>  
            <asp:Label ID="lblDateToday" runat="server"></asp:Label>  
                    <asp:Label ID="lblTime" runat="server"></asp:Label>  
                </ContentTemplate>  
                <Triggers>  
                    <asp:AsyncPostBackTrigger ControlID="TimerTime" EventName="Tick" />  
                </Triggers>  
            </asp:UpdatePanel>  
            </div>  
            <br />  

</div>

protected void Page_Load(object sender, EventArgs e)
{
        lblTime.Text = DateTime.Now.ToString("hh:mm:ss");


    }
    protected void TimerTime_Tick(object sender, EventArgs e)
    {
        lblTime.Text = DateTime.Now.ToString("hh:mm:ss");
    }


<asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:Timer ID="TimerTime" runat="server" Interval="1000">
        </asp:Timer>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
        <asp:Label ID="lblDateToday" runat="server"></asp:Label>
                <asp:Label ID="lblTime" runat="server"></asp:Label>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="TimerTime" EventName="Tick" />
            </Triggers>
        </asp:UpdatePanel>
        </div>
        <br />

查看 http://forums.asp.net/t/1528616.aspx?How+to+diplay+real+time+timing+clock+on+asp+net+web+page https://msdn.microsoft.com/en-us/library/ms172517(v=vs.90).aspx