I have a date object that's created by the user, with the timezone filled in by the browser, like so:
var date = new Date(2011, 05, 07, 04, 0, 0);
> Tue Jun 07 2011 04:00:00 GMT+1000 (E. Australia Standard Time)
不过,当我把它串起来时,时区就消失了
JSON.stringify(date);
> "2011-06-06T18:00:00.000Z"
在保留浏览器时区的同时获得ISO8601字符串的最佳方式是使用oment.js并使用moment.format()
,但当然,如果我通过内部使用JSON.stringify
的方式(在本例中为AngularJS)序列化整个命令,那么这将不起作用.
var command = { time: date, contents: 'foo' };
$http.post('/Notes/Add', command);
For completeness, my domain does need both the local time and the offset.