Reputation: 6752
I have an entity with a datetime object. The database time is 2012-05-07 00:00:00.000
and the data from the breeze web api call is coming as 2012-05-07T00:00:00.000
, but the property holding the data is Sun May 06 2012 20:00:00 GMT-0400 (Eastern Daylight Time)
. Note the 4 hour difference.
According to this:
[T]he timezone of the value on the server will be carried over to the value on the client (and vice versa).
It sounds like Breeze is treating the datetime as UTC and converting it to EDT. Is Breeze doing so based on the lack of timezone information from the original date? For this specific instance I do not care about Timezone, how do I get the actual date from the database regardless of client/server timezone?
Upvotes: 0
Views: 645
Reputation: 17052
You can replace Breeze's DataType.parseDateFromServer to NOT infer any time zone info if it is not provided:
breeze.DataType.parseDateFromServer = function (source) {
return new Date(Date.parse(source));
};
However, there is another problem you are likely to run into with this. Different browsers interpret DateTime strings without a time zone offset differently... So you may still get strange results depending on the browser. If that happens you will need to add some browser detection code to the snippet above.
EDIT: The suggestion was also made that if you use Moment.js you can do the following
breeze.DataType.parseDateFromServer = function (source) {
var date = moment(source);
return date.toDate();
};
Upvotes: 2