HI everybody,
I have a question about a component.
I am french and I am doing a weather app (to learn Ionic, I am a newbie ahah)
I want to display today’s date with HTML and I don’t know how to do.
Please can you help me ? All the subject about the time are about inputs and Ion-Datetime but this is not what I am looking for.
Thank you
1 Like
This came up often enough for me that I wrote a set of date pipes. You’re welcome to use them, or to write your own after looking at them.
English: https://www.npmjs.com/package/ng-datefns-pipes
international: https://www.npmjs.com/package/ng-datefns-pipes-all-locales
1 Like
In your TS file:
export class yourComponent {
today = Date.now();
}
in your html:
<p>{{today | date}}</p>
This will give you current date out of box.
Check bottom of this page:
https://angular.io/api/common/DatePipe
4 Likes
I use to get the date:
myDate: new Date().getTime()
and in HTML you can “choose” che format for your date…for example
{{myDate | date: 'dd/MM/yyyy'}}
will give you “24/05/18”
6 Likes
Hi,
I found what I have been looking for. I give my answer here, thanks to everybody.
My TS File :
now = new Date();
My HTML File :
{{now | date:'EEEE dd MMMM yyyy':'+0200':'fr'}}
That gives me (in french) : lundi 24 mai 2018
Thanks for all your answers
1 Like