开发者

Send date from client to server

I want to send data from clien开发者_高级运维t and create it on server. So:

1) How can I get the total milliseconds count by JavaScript Date object?

2) How can I create .NET DateTime object by total milliseconds count?


You will have to use AJAX for this. Once you send the d.getTime() as explained by the other answer, parse it like this in your C# code behind:

if (!string.IsNullOrEmpty(Request.Form["milliseconds"]))
{
    long clientSideMS = Int64.Parse(Request.Form["milliseconds"]);
    DateTime past = new DateTime(1970, 1, 1);
    DateTime clientSideDate = past.AddMilliseconds(clientSideMS);
}

After this, clientSideDate will be the date on the client side.

Edit: using jQuery, posting the date is as simple as:

var now = new Date();
var ms = now.getTime();
$.post("Page.aspx", { milliseconds: ms.toString() } );


var d = new Date();
alert(d.getMilliseconds()); // for the milliseconds between the current seconds
alert(d.getTime()); // for the milliseconds since Midnight, Jan 1, 1970
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜