本文介绍了客户端机器在asp.net中的日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我想要获取客户的机器日期&时间。
我用javascript这样做,
代码:
Hi guys,
I want to fetch client's machine date & time.
I have used javascript to do so,
code:
var currentTime = new Date();
var fulldate = currentTime.getFullYear()
+ '-' + currentTime.getMonth() + 1
+ '-' + currentTime.getDate()
+ ' ' + currentTime.getHours()
+ ':' + currentTime.getMinutes()
+ ':' + currentTime.getSeconds()
+ ':' + currentTime.getMilliseconds();
<% Session["CDATE"] = "'" + fulldate + "'" %>
但是,遗憾的是= =fulldate,就像字符串一样,我提供变量名称。
Plz建议我做什么...
谢谢
But, unfortunately sessions = "fulldate", like as string, where as i'm providing the variable name.
Plz suggest me what to do...
thanks
推荐答案
// Write this javascript code on <Head> tag of page and call it on window's load.
<script type="text/javascript">
window.onload = function () {
var currentTime = new Date();
var fulldate = currentTime.getFullYear()
// here converting the month number into integer and then adding 1 to it.
+ '-' + (parseInt(currentTime.getMonth()) + 1)
+ '-' + currentTime.getDate()
+ ' ' + currentTime.getHours()
+ ':' + currentTime.getMinutes()
+ ':' + currentTime.getSeconds()
+ ':' + currentTime.getMilliseconds();
// Save date in hidden field..
document.getElementById('<%=hdnDate.ClientID%>').value = fulldate;
}
I hope this solution will help you.. :)
</script>
//< Body>中的控件声明页面标签..
// Declaration of controls in <Body> tag of page..
<asp:hiddenfield id="hdnDate" runat="server" xmlns:asp="#unknown" />
<br />
<br />
<asp:button id="btnGetDate" runat="server" text="Button" onclick="btnGetDate_Click" xmlns:asp="#unknown" />
// On按钮单击,您可以在隐藏字段的帮助下访问服务器端的客户端日期..
// On Button Click, You can access client date at server side with help of hidden field..
protected void btnGetDate_Click(object sender, EventArgs e)
{
Response.Write(hdnDate.Value);
}
这篇关于客户端机器在asp.net中的日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!