Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ionic 2 datetime display current date to future date and focused on today's date

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!

like image 434
JSN Avatar asked Jan 04 '23 17:01

JSN


2 Answers

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.

like image 104
Stephan Strate Avatar answered Jan 25 '23 23:01

Stephan Strate


u can use this one too

currentDate: string = new Date().toLocaleDateString();

and it will look like this:

01/06/2018
like image 20
warabino Avatar answered Jan 25 '23 23:01

warabino