Take the 2-minute tour ×

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?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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();   
share|improve this answer
would using momentjs solve my problem? –  Jonas Stawski May 27 '13 at 21:29
Not sure, but worth a try. It's a very good library. –  Jay Traband May 28 '13 at 3:00
Jay, I got this to work by overriding breeze.DataType.parseDateFromServer. Also, calling Date(Date.parse(source)) was still converting it from UTC to local for some reason. I now use momentjs to create the date from the string and return the toDate to breeze. Here's my code: breeze.DataType.parseDateFromServer = function { var date = moment(source); return date.toDate(); }; Please correct your code so I can mark as Answer. –  Jonas Stawski Jun 18 '13 at 15:33
Jay, I had to add breeze.DataType in order to override it, otherwise it would give me an error as it doesn't know what DataType is –  Jonas Stawski Jun 18 '13 at 15:57
On all the examples I assume a "var DataType = breeze.DataType;" at the top of the module. But.. I should make this clearer. –  Jay Traband Jun 18 '13 at 17:37
add comment

Your Answer


