BUG: ion-datetime not in ISO 8601 Format

PLEASE DISREGARD… I FOUND MY ISSUE…

I am NOT getting the ISO 8601 Datetime Format: YYYY-MM-DDTHH:mmZ from the ion-datetime control

According to the docs for ion-datetime ionic uses the ISO 8601 datetime format for its value. However, I am getting the display format and not the ISO format

Here’s plunker that shows my issue. The ion-datetime control is as follows

<ion-datetime displayFormat="MMMM D, YYYY" pickerFormat="MMMM D, YYYY" [(ngModel)]="displaydate"></ion-datetime>

And a Save button that writes the selected date to the console

save() {
    console.log(this.displaydate);
  }

The date in the console is shown with the displayFormat “MMMM D, YYYY”. I was expecting an ISO format.

Am I missing something?

Would you mind posting what the issue was? Could help others who may run into the same issue.

@mhartington this is the issue I was having:

The output I get from the ion-datetime after I select a date is as follows: 2017-01-01

The following results in a deprecation warning: moment construction falls back to js Date

let dtDateISO = moment(this.displaydate, moment.ISO_8601);

The way to solve it and avoid the warning is to use the following format

let dtDateISO = moment(this.displaydate, 'YYYY-MM-DD');

I was under the impression, from reading the docs for the ion-datetime, that I would always receive an ISO_8601 formatted output. I guess not.

I’m under the impression that ‘YYYY-MM-DD’ is “an ISO_8601 formatted output”. Did you try just omitting the format parameter and just constructing with moment(this.displaydate)? That seems to work properly for me with no deprecation warnings. I think your definition of “must include time values” is overly narrow here.

@rapropos thanks for pointing that out. Using moment(this.displaydate) does work for me to. But when I do the same with another ion-datetime control that display hours and minutes, when I try moment(this.displaytime) it throws the warning

Is it perhaps because the date is not being included? If you can share some more code, perhaps we can resolve your underlying issue.

@rapropos take a look at this plunker

Run it, select a time, and click Save. Make sure you have a console open. You will get the deprecation warning

This throws the warning

   moment(this.displaytime)

But this does NOT

moment(this.displaytime, 'HH:mm')

Originally I thought this was a bug

That plunker gives me an error saying moment is not defined. Can you try priming your datetime component’s bound value? I think that makes the datetime component behave better.

displaytime = moment().toISOString();

Even just an arbitrary date like “2017-07-01” seems to work. That should give you something that the moment constructor will like.