Datetime component - show local time not UTC time?


I am using the new datetime component for alarms, and I want it initialized to the current time. When I pass the component an ISO string, it just shows the UTC time instead of the local time. It is 10:28 pm local time, but it is showing 2:28 am (UTC).

this.time=  new Date().toISOString()


<ion-datetime displayFormat="h:mm a" pickerFormat="h mm a" [(ngModel)]="time"></ion-datetime>


You need to process the timezone offset for this.


You can use this.time= moment.format();
It will automatically detect your timezone.


moment().format(); is correct


Error: While try to use that keyword Moment “Cannot find name ‘moment’”


Stop using moment. date-fns is much lighter and can work with either native Date objects or ISO8601 strings directly, instead of needing a dedicated object that is hard to work with.

Datetime in local time

So you are saying that date-fns is able to do everything that moment does and better ?


Absolutely. You only get what you need, whereas moment is a monolithic behemoth.