Hi friends,
I used ion-datetime but the selector shows the UTC time. I need to show my local time.
<ion-datetime [(ngModel)]="data" displayFormat="DD/MM/YYYY HH:mm" class="data-box"></ion-datetime>
I set “data” variable in my constructor. The string is local time but I show the UTC format.
Example. The time in Italy is 23:51. I set this.data = 03/07/2018 23:51 but when the input field will apear, I see 23:51
Support me please
Luca
Your post is confusing.
That sounds like you are seeing the time you want, no? ion-datetime
doesn’t care about timezones; it just deals with ISO8601 strings, so if you want the time and date you described, you just say:
this.data = "2018-07-03T23:51";
@lsantaniello … use moment js plugin
//install using command
>npm i moment
//ts
import * as moment from 'moment';
this.data = moment().format();
1 Like
The advice in the previous post will needlessly bloat your app binary significantly.
kocei
July 9, 2018, 12:18pm
6
@rapropos is a big fan of date-fns so I guess that’s the alternative, feel free to correct me If im wrong
I integrated moment. Can I use Pipe into my html file?
for example: {{p.data | moment:‘dd/MM HH:mm’}}
I receive error
{{[ERROR ->]p.data | moment:‘dd/MM HH:mm’}}
@lsantaniello you can directly use date pipe, there is no moment pipe in ionic.
1 Like
Thanks guys
I create my custom Pipe
import { Pipe, PipeTransform } from '@angular/core';
import * as moment from 'moment';
@Pipe({
name: 'moment',
})
export class MomentPipe implements PipeTransform {
transform(date, format) {
return moment(date).format(format);
}
}
usage:
<p>{{m.data | moment:'HH:mm'}}</p>
Thanks for support
1 Like