Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to get Client's time? I have a gridview in my Home page in which i am displaying all the details retrieved from my database. I want to update my table's status to expired if the client's time is greater than entered time. I have a webform which is a Request Form in which i am accepting time from the user and displaying it on my homepage.

I tried using this:
In Login.aspx :
JavaScript
<script type="text/javascript">

            window.onload = function () {

            var newdate = new Date();

            var hdnfield = document.getElementById('<%=hdnClientDate.ClientID%>');

                hdnfield.value = newdate.toLocaleString();

        }

    </script>


ASP.NET
<asp:HiddenField ID="hdnClientDate" runat="server" OnValueChanged="hdnClientDate_OnInit" />


In Login.aspx.cs:
C#
protected void hdnClientDate_OnInit(object sender, EventArgs e)    {

        Session["hdnClientDate"] = hdnClientDate.Value;

    }// saving the time in session
Posted
Updated 27-Aug-13 21:01pm
v5
Comments
Dholakiya Ankit 28-Aug-13 3:04am    
why you want to take clients time? your website can be accessed by client whose have time of 20/06/1990 so what will you do?
Member 10234846 28-Aug-13 3:56am    
in my gridview i am showing today and future dates only and deleting past date rows. and showing their status value in 'Status' Column as 'confirmed' . I have problem in time like if the current time is 12PM and user enters 11:50AM then i want to change 'Status' as Expired in the 'Status' Column of my gridview.
Dholakiya Ankit 28-Aug-13 4:26am    
so u have textbox for entering time right and current time is 12pm user enters 11.50 then that record will be shown as expired status
Member 10234846 28-Aug-13 4:33am    
I have two drop down ddlStarttime and ddlEndtime, initially they show current time like if it 11:50AM it will show 11:50AM but User can also select from the list item of my dropdown.
Dholakiya Ankit 28-Aug-13 4:51am    
but what you want to compare?

1 solution

Javascript is a client side scripting language, so you can use javascript to get the date and time of the browser. Just google for it and you will find a lot of samples. But if you don't want to use javascript, then you can also do it using ASP.Net. The following link may help you:
http://weblogs.asp.net/mikebosch/archive/2007/11/15/getting-the-client-browsers-date-and-time-with-asp-net.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900