日期格式在 ng-pick-datetime 中不刷新

问题描述

我有两个用户在两个不同的国家(印度和美国)。如果印度用户登录,我将日期格式更改为 DD/MM/YYYY,如果用户来自美国,我将格式更改为 MM/DD/YYYY。我的问题是,当印度用户登录日期更改为 DD/MM/YYYY 然后我注销并以美国用户身份登录它仍然是 DD/MM/YYYY。仅当我刷新时它才会更改为 MM/DD/YYYY登录成功后,我将国家的格式存储在localStorage中。

profile.component.html

          <input class="form-control" id="exampleInputEmail1" [max]="max" aria-describedby="emailHelp"
          #Birth="ngModel" [max]="max" (ngModelChange)="onChangeDate($event)" [(ngModel)]="dob"
          name="date" [owlDateTimeTrigger]="dt1" [owlDateTime]="dt1" required />
          <owl-date-time class="" [pickerType]="'calendar'" [startView]="'multi-years'" #dt1>
          </owl-date-time>

profile.component.ts

import { DateTimeAdapter,OWL_DATE_TIME_FORMATS,OWL_DATE_TIME_LOCALE } from 'ng-pick-datetime';
import { MomentDateTimeAdapter } from 'ng-pick-datetime-moment';
var format = localStorage.getItem('format');

export const MY_CUSTOM_FORMATS = {
  parseInput: format,fullPickerInput: format,datePickerInput: format,timePickerInput: 'hh:mm a',monthYearLabel: 'MMM-YYYY',dateA11yLabel: 'LL',monthYeara11yLabel: 'MMMM-YYYY'
};
@Component({
  selector: 'app-profile',templateUrl: './profile.component.html',styleUrls: ['./profile.component.scss'],providers: [
    { provide: DateTimeAdapter,useClass: MomentDateTimeAdapter,deps: [OWL_DATE_TIME_LOCALE] },{ provide: OWL_DATE_TIME_FORMATS,useValue: MY_CUSTOM_FORMATS }
  ]
})

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)