Domanda

I am sending some dates from Client Side to Server Side using Kendo Date Picker to WebApi. I am facing an issue when posting dates to WepApi. Getting wrong time at server end.

I have tried this on Chrome Console and getting the following results:

new Date("Wed Feb 12 2014 14:00:00 GMT+0530 (India Standard Time)"). toJSON()
"2014-02-12T08:30:00.000Z"      //TIME IS WRONG

new Date("Wed Feb 12 2014 14:00:00 GMT+0530 (India Standard Time)"). toUTCString()
"Wed, 12 Feb 2014 08:30:00 GMT"     //TIME IS WRONG

new Date("Wed Feb 12 2014 14:00:00 GMT+0530 (India Standard Time)"). toISOString()
"2014-02-12T08:30:00.000Z" 

//TIME IS WRONG
È stato utile?

Soluzione

The Date.toString() method should use the client time zone, if that's what you want:

new Date("Wed Feb 12 2014 14:00:00 GMT+0530 (India Standard Time)"). toString()

Of course, there are drawbacks:

  • The precise format will vary across browsers
  • Users from other time zones will send different values

If the API server is not able to parse time zone information, it's unlikely that it'll do the right thing with random formats. You should ask form documentation about the exact format and possibly build it manually.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top