我正在使用Date
将java script
对象解析为网络服务,如下所示。
HRA_Create.HelloWorld(new Date("2013-07-08 00:00:00"));
但是当我在Date
中检查此asmx 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>
的ScriptManager
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/HRA_Create.asmx" />
</Services>
</asp:ScriptManager>
Java脚本调用
<a href="javascript:callServer()">Call Server</a>
答案 0 :(得分:1)
您需要使用以下符合ISO 8601的W3C formats之一:
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"))