Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select Date and Time in 2 steps using Ionic DateTime

Select Date and Time in 2 steps using Ionic DateTime: I want to use Ionic DateTime selecting date and time. The problem is that the picker with pickerFormat="DD MMMM YYYY HH:mm" gets complicated and too narrow, so I want to select date first and just after select the time. Any idea about how to do so?

like image 577
Rafael López Martínez Avatar asked Mar 02 '18 21:03

Rafael López Martínez


People also ask

How does ionic display date and time?

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. Using the ISO datetime format makes it easy to serialize and parse within JSON objects and databases.

How do you use the Ionic 6 datetime component?

Adding Datepicker in Ionic 6 Template We use the ion-datetime component to add datepicker in Ionic app. Ionic date picker comes on the screen from the bottom of a page. You can separately choose Month, Date, Year, Hours and Minutes directly from scrollable columns which makes it great from the UX perspective.

How do you format an ionic date?

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.


1 Answers

You can always separate them like this

<ion-item [hidden]="!!myDate">
      <ion-label>Date</ion-label>
      <ion-datetime (ngModelChange)="change(datePicker)" displayFormat="MM/DD/YYYY" [(ngModel)]="myDate"></ion-datetime>
    </ion-item>
    <ion-item [hidden]="!myDate" >
      <ion-label>Time</ion-label>
      <ion-datetime #datePicker
      (ionCancel)="myDate=undefined" displayFormat="HH:mm" [(ngModel)]="myTime"></ion-datetime>
    </ion-item>

    <h1 [hidden]="!myTime">result is {{myDate}} : {{myTime}} </h1>

then in ts

change(datePicker){    
  datePicker.open();
}

Then concatenate the results

this.dateTime= this.myDate + ":" + this.myTime;

Here's a DEMO

like image 179
Melchia Avatar answered Sep 16 '22 16:09

Melchia