【问题标题】:I need get especific parametres(date, month, year) from value selected in ion-datetime我需要从 ion-datetime 中选择的值中获​​取特定参数(日期、月份、年份)
【发布时间】:2020-04-08 13:15:39
【问题描述】:

当从 ion-date 时间获取值并在控制台中打印时,只打印一个字符串。如何从选定的值中获取特定值(日期、月份、年份)?

这是我的代码:

fecha_nacimiento:Date;
public ageFromDOB($dateOfBirth) {
console.log($dateOfBirth);
}

HTML:

<ion-item>
      <ion-label position="floating">Fecha de nacimiento</ion-label>
      <ion-datetime type="date" displayFormat="MM/DD/YYYY" min="1920-03-14" max="2019-12-31"  
 [(ngModel)]="userre.fecha_nacimiento" (ionChange)="ageFromDOB($event)"></ion-datetime>
    </ion-item>

【问题讨论】:

    标签: typescript ionic-framework ionic4 ionic5


    【解决方案1】:

    试试这个

    public ageFromDOB($dateOfBirth) {
        console.log($dateOfBirth);
        console.log(new Date($dateOfBirth.detail.value).getFullYear());
        console.log(new Date($dateOfBirth.detail.value).getDate());
        console.log(new Date($dateOfBirth.detail.value).getMonth() + 1); // month value has index 0 so add 1 to it.
    
      }
    

    【讨论】:

      猜你喜欢
      • 2017-06-25
      • 2017-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-04
      • 2021-10-29
      • 2012-11-14
      • 2020-12-19
      相关资源
      最近更新 更多