0

I hate dates, I can never get them to behave. I have a javascript variable that looks like this:

var currentDate = new Date();

I pass this to a C# Web API controller as a parameter. My local time was 12:43 but when I put a breakpoint in my action it shows 11:43. The problem is, that if I do this at 00:43 then my controller would take the date as yesterday. I need it to pick out the right day. If I select the currentDate as 02/09/2015 12:43 then I need my controller to use the same date.

I know this has something to do with local times etc, but how can I get them all to use the same one?

Any help would be greatly appreciated.

8
  • You may need to do all your work with UTC dates. I'm not sure about javascript, but .NET has that capability. Commented Sep 2, 2015 at 11:50
  • Yeah, I already use UTC dates with C# but the problem is what JavaScript is passing. Commented Sep 2, 2015 at 11:51
  • passing dates between C# and javascript is always going to be hit and miss - we've resorted to using string representations (yyyymmdd) - it's messy, but guaranteed accurate Commented Sep 2, 2015 at 11:54
  • 1
    Send it to your API as a string. Then convert the string to a Date inside your controller. Of course, continue to use UTC time. Commented Sep 2, 2015 at 11:54
  • 1
    I suffered same issue. Now we used string parameters as its said here. stackoverflow.com/questions/6702705/… Commented Sep 2, 2015 at 11:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.