您的位置:首页 > 其它

服务器端获取客户端信息(时间 etc..)

2010-10-19 16:43 260 查看
能在client端写JavaScript,就尽量在客户端写。

格式化时间:

代码

//Register clientjs and hiddenfield to get client time with format "yyyy/MM/dd hh:mm:ss"
private const string CLIENTTIME_SCRIPT_ID = "__CLIENTTIMEJS";
private const string CLIENTTIME_FIELD = "__CLIENTTIME";
private string ClientTime
{
get
{
return this.Request.Form[CLIENTTIME_FIELD];
}
}
protected override void OnLoad(EventArgs e)
{
ClientScript.RegisterHiddenField(CLIENTTIME_FIELD, "");

if (!ClientScript.IsOnSubmitStatementRegistered(typeof(string), CLIENTTIME_SCRIPT_ID))
{
ClientScript.RegisterOnSubmitStatement(typeof(string),
CLIENTTIME_SCRIPT_ID, "var today = new Date();var year =today.getFullYear();var month =today.getMonth()+1;" +
"var day = today.getDate();var hours=today.getHours();var minutes=today.getMinutes();var seconds=today.getSeconds();" +
"document.getElementById('" +
CLIENTTIME_FIELD + "').value=year+'/'+formatWithZero(month)+'/'+formatWithZero(day)+' '+formatWithZero(hours)+':'+formatWithZero(minutes)+':'+formatWithZero(seconds)");
}

base.OnLoad(e);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: