1

I have an issue which I dont know if its a good feature or a bug .. :)

Just try those 2 lines of code (you can try angular-like or JSON.stringify, whatever)

console.log(angular.toJson(new Date()));  // ""2015-07-16T10:32:35.762Z""
console.log(new Date()); // Thu Jul 16 2015 12:32:37 GMT+0200 (CEST)

I would expect that date will be this same but... In first case its my local (GMT + 2), in second case its just 'jsonized'... but GMT! In my case -2 hours.

Do you know maybe what's a problem here? What is general rule :)?

MariuszJasinski
  • 504
  • 3
  • 8
  • maybe related : http://stackoverflow.com/questions/10286204/the-right-json-date-format , also Date Object has [`toJSON`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON) method – Hacketo Jul 16 '15 at 12:17
  • Yes, I figured out that Date has his own method - he acts this same as 'jsonized'. Its not local - just GMT. Provided topic its about 'the only only right' format of json Date object, not about 'jsonizing' :)) – MariuszJasinski Jul 16 '15 at 12:28
  • I have probably an answer.. I found at [link](http://stackoverflow.com/questions/18014341/how-to-convert-time-correctly-across-timezones) that method toISOString converts date to UTC format (+ documentation approves that ;) )So I suppose every 'toJSON' method uses toISOString method within.. :) So problem is solved - probably its default behaviour that 'jsonizing' converts date to UTC time. edit: if you want to jsonized local time, you have to use normal toString method :) – MariuszJasinski Jul 16 '15 at 12:46

0 Answers0