0

I've tried tons of things to fix this, but the problem continues to vex.

I have a Date field in SQL Server (not Datetime, because time doesn't matter), and a Java API (Spring actually) serves this field to my Ember front-end, where a user can edit the field (using an ember-pikaday input, but that may be immaterial).

The problem is that when I switch to edit mode, the date shows one date before, and if I save, that one date before is what gets saved. If I look at what the API is returning, it looks like the following: "2015-02-03T05:00:00.000+0000"

I'm still very much learning JavaScript (and Ember), so it looks like there's some local time zone information being used automatically (I'm in EST, which is GMT-5) and that's why it's returning the 5AM time.

I really don't want it to do anything at all with time, but as JavaScript date objects by definition include time info, I'm not sure how to get rid of it. I've tried setting the time to noon so that even with a five-hour difference, it will be the same day, but since the database doesn't save the time, the next time I refresh the page, I'm back to square one.

I've run out of things to Google, which is why I posted here. I'm sure I'm missing something obvious and easy.

EDIT: I tried creating a new variable to get just the date part and using that throughout, but when I go into Edit mode, where my Pikaday input comes into play, it still shows the date before, so I'm suspecting that's the cause of the issue, but I haven't seen hardly anyone else complaining of this.

redOctober13
  • 3,662
  • 6
  • 34
  • 61

1 Answers1

0

Here is a similar ember.js question:

Ember.js dates a day early

Also make sure your javascript ISO-8601 date has the timezone. I had a similar issue with web api where the ISO-8601 dates were not sending any timezone info and no Z for UTC and the receiver assumed they were not converted to UTC and made them a day earlier '2012-07-27T18:51:45.53403Z // UTC'. You could use Fiddler or Chrome dev tools to see the format of date you are sending to the server make sure the Z or offset '2012-07-27T11:51:45.53403-07:00 // Local' is there.

Community
  • 1
  • 1
kmcnamee
  • 5,097
  • 2
  • 25
  • 36
  • I don't think it does. When I look at the API response in dev tools, the date looks like this: "2015-02-03T05:00:00.000+0000" It doesn't matter really what I send back to the API since the database doesn't have the time info. So are you suggesting that I just change the API to return "Z" at the end of the time rather than the "+0000"? Do you think that would solve it? – redOctober13 Feb 04 '15 at 16:07
  • 1
    no changing +0000 to z should not matter. Javascript date object always includes a time piece even if you dont care about it. Once you start passing this between client server this becomes more obvious because it will get serialized. Check out this [jsfiddle](http://jsfiddle.net/c8zb5ezt/) new Date('2014-02-04'); will become febuary 3rd when converted to EST if you disregard the time part. – kmcnamee Feb 04 '15 at 18:48
  • So if I can't prevent JS from putting in time information, what can I do. As I mentioned above, the date returned from the API is 5am GMT, so on EST, you're at midnight, but anywhere further west, it creeps into the day before. Since the database is just a date, with zero time zone info, what's the right way to send data through the API so that my front end always shows the same day? – redOctober13 Feb 04 '15 at 20:27