0

why when i convert time JSON.stringify why my time change please help me how to handle this please anyone help me , and how to direct json transfer Code behind C# variable

subject_end: Thu Jan 01 1970 09:00:00 
After JSON.stringift
"subject_start":"1970-01-01T03:00:00.000Z" 
i don't know why this happen

     $scope.Savesujects = function (item, event) {
                            console.log($scope.moreadditems);
                            var getjsonvar = JSON.stringify($scope.moreadditems);
                            console.log(getjsonvar);
                            var ssa = String(getjsonvar);
                            $.ajax({
                                type: "POST",
                                url: "classschedule.aspx/savesubhects",

                                data: JSON.stringify({ jsonstring: ssa }),
                                contentType: "application/json; charset=utf-8",
                                dataType: "json",
                                success: function (msg) {
                                    alert(msg.d);

                                },
                                error: function (msg) {
                                    alert(msg.d);
                                }
                            });
                        }

//CODE BEHINED 

    [WebMethod]
            public static string savesubhects(string jsonstring)
            {}

enter image description here enter image description here

Addi Khan
  • 201
  • 2
  • 15

2 Answers2

0

JSON considers date time in UTC. This is why you are seeing the datetime value changed when you call JSON.stringify

Either you can store this date time as UTC or do the required culture specifc conversion at C# end.

Kalyan
  • 1,200
  • 1
  • 11
  • 23
0

I can't say for sure because you scribbled out the time zone (why?) but I think it says +05:00 - It looks like you are seeing the exact same time represented two different ways. Once in the local time zone (+5 hours) and one in UTC time without timezone added. See this SO for the same issue

EDIT: Generally the best practice for time is to handle and store it in UTC time, and convert it to the local timezone when displaying. For websites you can use a framework like moment.js to do the conversions simply

Community
  • 1
  • 1
Kirlac
  • 684
  • 6
  • 18