0

I have local date and UTC date.I need to convert the dates in a webpart according to browser timezone. I get the local browser time from javascript and store that in hidden variable.

<script type ="text/javascript" >
$(document).ready(getCLientDate);
function getCLientDate() {
    var currentDate = new Date();
    var hiddenDate = $("#<%= hdnDate.ClientID %>").val(currentDate);
   // alert(hiddenDate);
}

The value in hidden variable is accessed on server side. Also i get the current UTC date from server side.

I have some existing dates which I need to convert without postback, hence the hidden value. Please guide on how to approach further.

 public void ConvertEventDate(string localDate)
    {
        var CurrentlocaltimehdnDate = hdnDate.Value;
        var currentUTCTime = DateTime.UtcNow;
        row["Date"] = Convert.ToDateTime(item["EventDate"].ToString()).ToString("dd MMM yyyy");//getting from sql 



       //TO: How to convert the existing row["Date"]

    }
Deepika
  • 290
  • 1
  • 5
  • 17
  • You cannot! you have to grab the time from the browser maybe during the initial PostBack and store it in a Hidden Field / View State / Session... etc. If that is a service, you can pass the current time as one of the parameters. – yazanpro Jun 22 '15 at 15:45
  • I get the current time during pageload itself; in $(document).ready(getCLientDate); function. What the need is how to how to use it to convert the existing dates and show them back on browser – Deepika Jun 22 '15 at 15:49
  • Let's say you detect that there is a 3 hours difference between the browser time and UTC, then you convert the database date (which I will assume it's saved as UTC, otherwise you work things out accordingly) and add 3 hours. – yazanpro Jun 22 '15 at 15:56
  • The question I marked as dup is not *exact* duplicate, but close enough. The answer has all of the relevant information. If you need more details, search for [questions that reference "jsTimeZoneDetect"](http://stackoverflow.com/search?tab=votes&q=jstimezonedetect). – Matt Johnson-Pint Jun 22 '15 at 21:55

0 Answers0