如何为可编辑日期设置正确的日期格式

Ale*_*rff 7 javascript date angularjs node-postgres x-editable

我从postgres获得一些日期文件,格式如下:

"2000-11-30T14:00:00.000Z"

我无法在页面上的可编辑日期字段中使用此功能.就像是:

 <a href="#" editable-date="employee.brthday"
     onbeforesave="updateField($data, 'brthday', employee)">
         {{employee.brthday || 'empty' | date:"dd/MM/yyyy" }}
 </a>
Run Code Online (Sandbox Code Playgroud)

这个日期(如上所示)显示正常.但是,当我想编辑此字段时,日期将重置,我在控制台中收到此消息:

Error: [ngModel:datefmt] Expected `2000-12-05T14:00:00.000Z` to be a date http://errors.angularjs.org/1.3.0/ngModel/datefmt?p0=2000-12-05T14%3A00%3A00.000Z
    at http://localhost:8000/bower_components/angular/angular.js:80:12
    at Array.<anonymous> (http://localhost:8000/bower_components/angular/angular.js:19453:17)
    at Object.ngModelWatch (http://localhost:8000/bower_components/angular/angular.js:20555:36)
    at Scope.$digest (http://localhost:8000/bower_components/angular/angular.js:13957:40)
    at Scope.$apply (http://localhost:8000/bower_components/angular/angular.js:14227:24)
    at HTMLAnchorElement.<anonymous> (http://localhost:8000/bower_components/angular-xeditable/dist/js/xeditable.js:831:21)
    at HTMLAnchorElement.jQuery.event.dispatch (http://localhost:8000/bower_components/jquery/dist/jquery.js:4409:9)
    at HTMLAnchorElement.elemData.handle (http://localhost:8000/bower_components/jquery/dist/jquery.js:4095:28)
Run Code Online (Sandbox Code Playgroud)

如果我只是通过编辑字段来更新模型(输入新日期),将来可以编辑正常,因为日期存储如(Date obj?):

Wed Dec 06 2000 00:00:00 GMT + 1000(Якутскоевремя(зима))

如何将输入日期转换为角度格式可理解?
我还尝试用'new Date(输入日期 - 这里)替换输入日期格式,但它不起作用.可能是输入日期格式无法从字符串中解析?

总结:我需要将输入日期格式转换为Date obj或通过像Date对象这样的pg.js日期字段获取.我该怎么做呢?

she*_*erb 4

Postgres 以 ISO 8601 格式存储日期,JavascriptDate可以开箱即用地解析该格式,例如:

var x = new Date("2000-11-30T14:00:00.000Z");
console.log(x);
Run Code Online (Sandbox Code Playgroud)

结果Thu Nov 30 2000 06:00:00 GMT-0800 (PST)对于我的时区来说是正确的。