Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set right date format for editable-date

I getting some date fileds from postgres with format like:

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

I can't use this in my editable-date field on page. Something like:

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

This date (like above) displayed fine. But when I want edit this field, date will reset and I got this message in 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 model by editing the field (input new date), It could be edit fine in future, because date stored like (Date obj?):

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

How can I convert my input date, to understandable for angular format?
I also tried to replace input date format with 'new Date(input-date-here), but it doesn't work. May be input date format can't be parsed just from string?

Summarizing: I need convert input date format to Date obj OR get via pg.js date fields like Date objects. How can I do something from that?

like image 217
Maksim Nesterenko Avatar asked Nov 09 '14 05:11

Maksim Nesterenko


People also ask

How do I create a custom date format?

Create a custom date formatPress CTRL+1. In the Format Cells box, click the Number tab. In the Category list, click Date, and then choose a date format you want in Type. You can adjust this format in the last step below.

How do I format a date in DD MMM YYYY in Excel?

First, pick the cells that contain dates, then right-click and select Format Cells. Select Custom in the Number Tab, then type 'dd-mmm-yyyy' in the Type text box, then click okay. It will format the dates you specify.

How do you automatically format dates in Excel?

To change the date or time format, right-click on a cell, and select Format Cells. Then, on the Format Cells dialog box, in the Number tab, under Category, click Date or Time and in the Type list, select a type, and click OK.

How do I make the date automatically update when a cell changes?

Right-click your cell with the current date and select Format Cells. Choose the date format you wish to use for the date. Each time you open the spreadsheet, this cell automatically updates to the current date, in the format of your choosing.


1 Answers

Postgres is storing the 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);

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

like image 128
sherb Avatar answered Oct 16 '22 16:10

sherb