question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UTC Date format not recognized

See original GitHub issue

Bug

I am trying to bind a property with the value “2008-10-28T00:00:00+01:00” to my material datepicker. I configured it like that:

                    <md-input-container>
                        <input mdInput 
                                [mdDatepicker]="picker2"                              
                                [formControl] = "myForm.get('MyDate')" 
                                placeholder="My date" 
                                [(ngModel)]="myDate">
                        <md-datepicker-toggle mdSuffix [for]="picker2"></md-datepicker-toggle>
                        <md-datepicker #picker2></md-datepicker>  
                    </md-input-container> 

So “myDate” has a UTC Timestamp value. I am receiving the error message:

Datepicker: value not recognized as a date object by DateAdapter

I tried to fix this, with configuring my own Date adapter:


        export class AppDateAdapter extends NativeDateAdapter { 
                format(date: Date, displayFormat: Object): string {
                    console.log(date);
                    if (displayFormat === 'input') {
                        const day = date.getDate();
                        const month = date.getMonth() + 1;
                        const year = date.getFullYear();
                        return `${day}-${month}-${year}`;
                    } else {
                        return date.toDateString();
                    }
                }
            }
         export const APP_DATE_FORMATS =
         {
             parse: {
                 dateInput: { month: 'short', year: 'numeric', day: 'numeric' },
             },
             display: {
                 dateInput: 'input',
                 monthYearLabel: { year: 'numeric', month: 'numeric' },
                 dateA11yLabel: { year: 'numeric', month: 'long', day: 'numeric' },
                 monthYearA11yLabel: { year: 'numeric', month: 'long' },
             }
         };


@Component({
    selector: "",
    templateUrl: "my-form.component.html",
    styles: [":host /deep/ .ui-dropdown{ width: 100% !important;}"],
    providers: [{provide: DateAdapter, useClass: AppDateAdapter}, 
                {provide: MD_DATE_FORMATS, useValue : APP_DATE_FORMATS }]

})

In my “format”-function I tried to output the value the adapter receives, but the error is thrown even before. Anybody knows what I could do? Is there even a way for UTC Timestamp? I do not need the time. It should be ignored by the picker.

What is the expected behavior?

Support for UTC Datetime

What are the steps to reproduce?

Trying to bind the value “2008-10-28T00:00:00+01:00” to the datepicker.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
koiszzzcommented, Sep 1, 2017

I have met the same problem . Background server send 2017-09-19 16:00:00.000Z to browser, the data model seem cannot change the string to Data type, so I change the string by using MODEL.date = new Date(the string)

0reactions
angular-automatic-lock-bot[bot]commented, Sep 7, 2019

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ORA-01821: date format not recognized error for ISO 8601 ...
You have two issues: TO_DATE doesn't recognise any time zone components or fractional seconds, you'll have to convert it to timestamp with ...
Read more >
Date value Error ORA-01821: date format not recognized
Hi Team, will executing the below query i am getting ORA-01821: date format not recognized. SELECT DISTINCT to_date(TO_CHAR(csactivated ...
Read more >
Date format not recognized - Snowflake Community
Hi all,. I am trying to load data from a CSV file (using snowpipe). The date is stated in the following format: M/D/YYY...
Read more >
Documentation: 15: 8.5. Date/Time Types - PostgreSQL
In most cases, a combination of date , time , timestamp without time zone , and timestamp with time ... -8:00, UTC offset...
Read more >
Date.parse() - JavaScript - MDN Web Docs
The Date.parse() method parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found