ion-datetime: How to get date value without timestamp? ion-datetime: How to get date value without timestamp? angular angular

ion-datetime: How to get date value without timestamp?


If you want only date then I think split() method might works,beacause value we get from ion-datetime is a string.So we use split method which split string and convert it to an array,and you can get date or time which thing you want with the help of index as follow:

     var dateFormat = mydate.split('T')[0];      console.log(dateFormat);     // 2019-04-22


You can format the date with Moment.js.

<ion-datetime displayFormat="MMM DD, YYYY" max="2030" min="2019" [(ngModel)]="mydate" (ionChange)="doSomething(this.mydate)"></ion-datetime>import * as moment from 'moment';doSomething(date) {   console.log('date', moment(date).format('YYYY-MM-DD')); // 2019-04-22}


You can use custom picker options to set custom buttons, it returns an object with all the variables in separate keys, so it makes it easier to edit the way you want it to display

To do so, you would insert this in your ion-datetime

[pickerOptions]="customPickerOptions"

and in your .ts file

this.customPickerOptions = {            buttons: [                {                    text: 'Save',                    handler: (time) => {                        console.log('time', time);                    }                },                {                    text: 'Cancel',                    handler: e => {                        modalCtrl.dismiss(e)                    }                }            ]        }

Hope this helps