在 angular 中有条件地更改 owl-日期时间选择器的日期格式

Conditionally change date format of owl-date-time picker in angular

我在 5 月的项目中使用了 owlDateTime(https://daniel-projects.firebaseapp.com/owlng/date-time-picker) 选择器。 选择日期后,它显示 mm/dd/yyyy 格式,但我想有条件地将此格式更改为 dd/mm/yyyy。

下面是我的代码 .component.html

<input [max]="max" [owlDateTimeTrigger]="dt_date_time" [owlDateTime]="dt_date_time" formControlName="date_time" id="date_time" type="text" class="form-control date-picker date-field hasDatepicker" placeholder="dd/mm/yyyy" name="date_time" value="">
<owl-date-time  [pickerType]="'calendar'" #dt_date_time></owl-date-time>

我已经使用以下代码解决了上述问题

import { Component, OnInit } from '@angular/core';
import { DateTimeAdapter } from 'ng-pick-datetime';



@Component({
  selector: 'app-home-layout',
  templateUrl: './home-layout.component.html',
  styleUrls: ['./home-layout.component.css']
})
export class HomeLayoutComponent implements OnInit {

  constructor(dateTimeAdapter: DateTimeAdapter<any>) { 

    let UserAttributes=JSON.parse(localStorage.getItem('UserAttributes'));
    let country= UserAttributes['custom:country'];
    if(country=='USA'){
       dateTimeAdapter.setLocale('us');
    }else{
       dateTimeAdapter.setLocale('en-IN');
    }

  }

  ngOnInit() {

  }

}