0

我正在使用如下Date方式将对象解析为 Web 服务。java script

HRA_Create.HelloWorld(new Date("2013-07-08 00:00:00"));

但是当我签入时Dateasmx WebMethod显示为7/7/2013 6:00:00 PM

我调试我的应用程序并看到如下值。

Debug.WriteLine(dt.ToString());

可能是什么错误?我该如何解决这个问题?

    [WebMethod]
    public string HelloWorld(DateTime dt)
    {
        Debug.WriteLine(dt.ToString());

        return dt.ToString();
    }

Java 脚本

<script type="text/javascript">
    function callServer() {
        HRA_Create.HelloWorld(new Date("2013-07-08 00:00:00"));
    }
</script>

脚本管理器

<asp:ScriptManager ID="ScriptManager1" runat="server">
    <Services>
        <asp:ServiceReference Path="~/HRA_Create.asmx" />
    </Services>
</asp:ScriptManager>

Java 脚本调用

<a href="javascript:callServer()">Call Server</a>
4

1 回答 1

1

您需要使用以下符合 ISO 8601 的W3C 格式之一:

Year:
   YYYY (eg 1997)
Year and month:
   YYYY-MM (eg 1997-07)
Complete date:
   YYYY-MM-DD (eg 1997-07-16)
Complete date plus hours and minutes:
   YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)
Complete date plus hours, minutes and seconds:
   YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)
Complete date plus hours, minutes, seconds and a decimal fraction of a second
   YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)

where:

YYYY = four-digit year
MM   = two-digit month (01=January, etc.)
DD   = two-digit day of month (01 through 31)
hh   = two digits of hour (00 through 23) (am/pm NOT allowed)
mm   = two digits of minute (00 through 59)
ss   = two digits of second (00 through 59)
s    = one or more digits representing a decimal fraction of a second
TZD  = time zone designator (Z or +hh:mm or -hh:mm)

在您的示例中,以下任何一项都应发送正确的日期:

HRA_Create.HelloWorld(new Date("2013-07-08T00:00:00Z"));
HRA_Create.HelloWorld(new Date("2013-07-08"))
于 2013-07-08T08:54:11.353 回答