无法获得服务器时间asp.net

时间:2016-04-14 18:10:31

标签: asp.net vb.net forms

我正在尝试获取服务器时间而不是客户端日期和时间。当我使用这段代码时,它会让我在计算机上更改时间。我想让它只是保持服务器时间。

<script runat="server">

    Protected serverTime As DateTime = System.DateTime.Now()

</script>

我在这里用我的asp形式输出

<%= serverTime.ToString()%>

1 个答案:

答案 0 :(得分:1)

以下任何一项都有效:

Protected serverTime As String = System.DateTime.Now.ToString();
Protected serverTime As String = System.DateTime.Now.ToLongDateString();
Protected serverTime As String = System.DateTime.Now.ToLongTimeString();
Protected serverTime As String = System.DateTime.Now.ToShortDateString();
Protected serverTime As String = System.DateTime.Now.ToShortTimeString();