0

I want to fetch browser date automatically on a page,

The controller code is as follows:-

HttpCookie myCookies = Request.Cookies["MemberID"];
int memberid = int.Parse(myCookies.Value);
var notes = data.Notes.ByCreatedBy(memberid);
return View(notes);

Now in the View, I am displaying values as The notes of current date only should get displayed:-

if (@DateTime.Now.Day == item.CreatedOn.Value.Day && @DateTime.Now.Month == item.CreatedOn.Value.Month && @DateTime.Now.Year == item.CreatedOn.Value.Year)
{
<li class="track_notes_li" id='@item.NoteID'><a href="/Notes/Index/@item.NoteID"><span class="first_word">@item.Description,</span> <span>@item.CreatedOn.Value.ToShortDateString()</span></a></li>
}

The problem is , the date it is taking in DateTime.Now is the date of the server. So I will get issues when timezone is different. I want to know how to get the browser date so that the current day notes irrespective of timezones should get displayed.

tereško
  • 58,060
  • 25
  • 98
  • 150
Neharika
  • 95
  • 11
  • 1
    take a look at this SO post: http://stackoverflow.com/questions/12896613/localization-how-to-get-the-client-locale-in-asp-net-mvc – Hardrada Feb 24 '14 at 08:20

1 Answers1

0

If you can set a cookie via javascript before this step, it is easy

new Date().getTimezoneOffset(); will give you the value you want.

If you can't do that, you will need to detect the user's IP address, map that, and look up the tiemzone of that area.

Patrick
  • 13,872
  • 5
  • 35
  • 53