Ionic2 Datetime Picker Default value


#1

im use ionic 2 datetime picker to my application,

but it show like this not show default date time,i want like this

then i want to add default value as current date and time, i think any one can give solution for this…


Date picker default time is current time not the field value
#2

**

Find Answer

**

ISO 8601 Datetime Format: YYYY-MM-DDTHH:mmZ

Ionic uses the ISO 8601 datetime format for its value. The value is simply a string, rather than using JavaScript’s Date object. Additionally, when using the ISO datetime format, it makes it easier to serialize and pass within JSON objects, and sending databases a standardized format which it can be easily parsed if need be.
So all you need to do is parse in the ISO string date format instead of the date object itself
like so

this.myDate = new Date().toISOString();

and use it in the HTML like so

<ion-datetime displayFormat="MMM DD, h:mm A" [(ngModel)]="myDate"></ion-datetime>