Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open ion-datetime in local timezone

I've got an Ionic app that dynamically creates a form that sometimes has an ion-datetime in it. The date time is also optional on the form, so it is not have an initial value set by me.

<ion-datetime *ngIf="question_definition.component == 'date'"
     displayFormat="DD MMM, YYYY HH:mm"
     pickerFormat="DD MMM YYYY HH:mm"
     [formControlName]="question_definition.question">
</ion-datetime>

Currently when a user taps on the element the data picker appears and is set to the time using UTC. I'm in New Zealand and want it to use +12:00 time (at the moment, until daylight saving starts).

How do I get an ion-datetime without a value to open up and display the time in my local timezone?

like image 884
Craig Avatar asked Nov 20 '25 07:11

Craig


1 Answers

After digging alot... Found answer.

ion-datetime apparently has an undocumented attribute called initialValue. So, if you want to get a different timezone, you can do this

.html

<ion-datetime [initialValue]="myInitialTime" pickerFormat="HH:mm" [(ngModel)]="myTime"></ion-datetime>

.ts

this.myInitialTime = localDate
like image 86
Avinash Yalgonde Avatar answered Nov 22 '25 03:11

Avinash Yalgonde



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!