Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to dynamically change time format from 12 hour to 24 hour or vice versa #114

Open
ParulChak opened this issue Dec 29, 2021 · 0 comments

Comments

@ParulChak
Copy link

ParulChak commented Dec 29, 2021

I am using the angular version of flatpicker. In this I want a functionality like changes the time format from 24h to 12 h or vice versa by using external button of time format.

.ts code configuration of flatpicker
` ```
dateTimePicker: FlatpickrOptions = {
altInput: true,
altInputClass: 'flatPicker',
enableTime: true,
altFormat: 'M j, Y H:i',
dateFormat: 'Y-m-d H:i',
minDate: 'today',
time_24hr: true,
defaultDate: new Date().ISOString(),
disableMobile: true
};

toggleTimeFormat(value) {
if(value === '12h') {
this.dateTimePicker.time_24hr = false;
this. dateTimePicker,altFormat: 'M j, Y H:i',
dateTimePicker.dateFormat: 'Y-m-d H:i',
}
}



`.html code of flatpicker`
    ` ```
<ng2-flatpickr [config]="dateTimePicker"
                       formControlName="date" >
        </ng2-flatpickr>
      <div class=" m-0 p-0">
          <button [ngClass]="{'tabColor': timeFormat === '12h'}"
                  class="p-2 pl-3 pr-3 rounded-left border-right-0"
                  (click)="toggleTimeFormat('12h')">
            12 HOURS
          </button>
      </div>
      <div class="m-0 p-0">
          <button [ngClass]="{'tabColor': timeFormat === '24h'}"
                  class="p-2 pl-3 pr-3 rounded-right border-left-0"
                  (click)="toggleTimeFormat('24h')">
            24 HOURS
          </button>
      </div>

Anybody suggest me, how I can achieve this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant