Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear All,

I have ASP.NET web application, where i have created one page to book slots, in which i'm using Jquery fullCanlendar control to select multiples days.

But the problem here is, if client change its machine date then this fullcalendar is showing the current date, what client had set in his/her machine's date.

for eg:
today is 20th march, 2017. And if i set my machine date to 19th march, 2017. Then the jquery fullcanlendar control is showing the starting date as 19th march, 2017., which is totally wrong.

What I have tried:

I want to display fullcalendar control current date, compare to the server date.

If the client changes his/her machine date & time, it should not effect the application.

Can any one please help to solve this issue...


Thanks
Posted
Updated 19-Mar-17 23:23pm
v3

1 solution

JavaScript picks the date from the client Machine DateTime value, This is how it works, If you want to use the server date, then store the current date in a hidden field and the use it across the JavaScript code.

ASP.NET
<asp:HiddenField ID="hdnServerDate" runat="server" />

JavaScript
<script>

        var serverDate = document.getElementById('<%= hdnServerDate.ClientID %>').value; 

    </script>


C#
protected void Page_Load(object sender, EventArgs e)
        { 
            if (!Page.IsPostBack)
            {
                hdnServerDate.Value = DateTime.Now.ToShortDateString();              
            }
        }


Updated solution, based on F-ES Sitecore comments

simplest way of doing
var serverDate = '<%= DateTime.Now.ToString("dd MMM yyyy") %>';
 
Share this answer
 
v2
Comments
F-ES Sitecore 20-Mar-17 5:38am    
You can ditch the hidden field and just do

var serverDate = '<%= DateTime.Now.ToString("dd MMM yyyy") %>';

The OP should ensure the date format used is the format needed by his calendar rather than using ToShortDateString or any other function that uses formatting based on server-side configuration.
Karthik_Mahalingam 20-Mar-17 5:44am    
Yes! very simple and does the job.

"ToShortDateString()" is just for an example.

updated the solution.
abdul subhan mohammed 20-Mar-17 5:47am    
Thanks all

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