Here I would like to share easy code to get client side time.
In many case we need to show the client side time.
Take scenario you host your website on UK server, but the
user accessing your site from India, and he try post some content on your website.
Here you have to show the client side posting time. If you get the time from
server it will show UK time, which means its wrong time because of time difference
between two countries.
So to overcome above problem you can easily solved by using JavaScript.
<script type="text/javascript">
function getTime()
{
TimeFd = document.getElementById("ClientTime");
clientDate = new
Date();
// return hours and minutes so we don't have to
// worry about 12/24 hour settings.
TimeFd.value =
clientDate.getHours() + ":" + clientDate.getMinutes();
}
</script>
|
On body tag you should call the JavaScript function on which
page loads its will call the function to display client side time.
<body onload="getTime();">
<asp:HiddenField ID="ClientTime" runat="server" />
</form>
</body>
|
That’s it .By using the above method you can easily store
the client side time value.
Post your Comments Here
0 comments:
Post a Comment