How do I convert the UTC date time to local time Jquery
<p>I insert 2012-12-11 1pm (I am in Ontario which is EST) into a web form and post it to my <strong>local web server</strong>, and convert it to <strong>UTC</strong> time (Asp.Net start_date = CDate(start_date).ToUniversalTime ) before I save it in the database.  The UTC time is 6pm in the database field.  I use the following code (see below) to convert the saved UTC date time to the user and it happily displays 1pm (GMT-5:00).</p>

<p>When I post the same time of 1pm on my production server which is in california the saved time in the database is 9pm.  So GMT-8:00 should give me 1pm on the client's browser.  The time displayed via the production server is <strong>7pm</strong>? Why and is there a fix?</p>

<p>I return the value from the database via an asp.net json and then use moment.js to convert it to a UTC number and then run the utcToLocal function. <strong>How do I display the expected 1pm?</strong> </p>

<pre><code> function utcToLocal(utc) {
            // Create a local date from the UTC string
            var t = new Date(Number(utc));

            // Get the offset in ms
            var offset = t.getTimezoneOffset() * 60000;

            // Subtract from the UTC time to get local
            t.setTime(t.getTime() - offset);

            // do whatever
            var d = [t.getFullYear(), t.getMonth(), t.getDate()].join('/');
            d += ' ' + t.toLocaleTimeString();
            return d;
        }

    //.format("YYYY-MM-DD h:mm a")
        function Get_History(filter_date, msg) {
            //div_history

            var jsonText = JSON.stringify({
                filter_date: filter_date, UserID: userid
            });

            $.ajax({
                type: "POST",
                url: "cc_m.aspx/getHistory",
                data: jsonText,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    if (data.d != "0") {
                        var obj = $.parseJSON(data.d);
                        $('.div_history').html('');
                        $.each(obj, function (index, value) {
                            $('.div_history').append(                                    
                                "&lt;div class='grid_history' style='border: solid 1px silver;'&gt;" +                                               
                                "Group: " + value.Group_Name + "&lt;br/&gt;" +
                                "Teacher: " + value.Teacher + "&lt;br/&gt;" +
                                "Child: " + value.Child_Name + "&lt;br/&gt;" +
                                "Category: " + value.Category + "&lt;br/&gt;" +
                                "Item: " + value.Item + "&lt;br/&gt;" +
                                "From: " + utcToLocal(moment.utc(value.Start_Date)) + "&lt;br/&gt;" +
                                "To: " + utcToLocal(moment.utc(value.End_Date)) + "&lt;br/&gt;" +
                                "Note: " + value.Other + "&lt;br/&gt;" +
                                "Status: " + value.Status + "&lt;br/&gt;" +
                                "&lt;fieldset data-role='controlgroup' data-type='horizontal' data-mini='true' &gt;" +
                                "&lt;button class='send_item' rel='" + value.id_Group + "' data-icon='envelope' data-theme='b' &gt;Send&lt;/button&gt;" +
                                "&lt;button class='edit_item' rel='" + value.id + "' data-icon='edit' data-theme='a' &gt;Edit&lt;/button&gt;" +
                                "&lt;button class='reset_item' rel='" + value.id + "' data-icon='repeat' data-theme='a' &gt;Reset&lt;/button&gt;" +
                                "&lt;a data-role='button' class='delete_item' rel='" + value.id + "' data-icon='remove' data-theme='a' href='#popup_delete' data-rel='dialog'&gt;Delete&lt;/a&gt;&lt;br/&gt;" +
                                "&lt;/fieldset&gt;&lt;/div&gt;&lt;br/&gt;"    

                            );
                            $(".div_history").trigger("create");
                            //on add history update msg at top of page to NEW RECORD! or ACTIVITY RECORDS SENT! or ACTIVITY RESET TO PENDING! and scroll to top
                            //if (msg.length &gt; 0) {
                            $(".grid_msg").html(msg);
                            //}
                        });

                        }
                    } //end success
            });

        }
</code></pre>
