How to set the correct date format for an editable date

I get some date tokens from postgres with a format like:

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

I cannot use this in my editable date field on the page. Something like:

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

This date (e.g. above) is displayed in a fine. But when I want to change this field, the date will be reset, and I received this message in the console:

 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) 

If I just update the model by editing the field (enter a new date), it may be right in the future, because the date is stored as (Date obj?):

Wed Dec 06 2000 00:00:00 GMT + 1000 (Yakut time (winter))

How can I convert the input date that is understandable to the angular format?
I also tried replacing the input date format with a new date (date-date-here), but it doesn’t work. Maybe the input format cannot be parsed from just a string?

To summarize: I need to convert the input date format to Date obj OR get through pg.js date fields, such as Date objects. How can I do something about this?

+7
javascript date angularjs node-postgres x-editable
source share
2 answers

Postgres saves dates in ISO 8601 format, which Javascript Date can parse out of the box, for example:

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

leads to Thu Nov 30 2000 06:00:00 GMT-0800 (PST) , which is correct for my time zone.

+4
source share

I found the answer for me ... I tried converting the input date to Date obj on the server side, and then sent json to the client. On the client, I always got my date as a string, but not as a Date object. When I make a new date (inputDate) on the client, everything is fine.

+2
source share

All Articles