I'm currently developing an app using ionic 2.
My problem is about datetime: I have this code in my html
<ion-item>
<ion-label stacked>Date</ion-label>
<ion-datetime [(ngModel)]="date" formControlName="date" displayFormat="MMMM DD, YYYY" min="2017" max="2100"></ion-datetime>
</ion-item>
The result is this => http://prntscr.com/fz5lx6
But I want to focus it to current date not to the maximum date.
How can I set that in ionic 2?
Any help is much appreciated. Thanks!
The [(ngModel)]="date"
is the right way to do it.
Now you can declare following variable in your Typescript file:
public date: string = new Date().toISOString();
This way, you creating a date, based on the actual time and formating it into a string that the <ion-datetime>
component can work with.
A proper string could look like this:
2017-07-23T09:10:19.621Z
In this case you do not need the time behind the date, because you only use the date.
u can use this one too
currentDate: string = new Date().toLocaleDateString();
and it will look like this:
01/06/2018
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With