Show today's date on Ionic


#1

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 :slight_smile: :slight_smile: :slight_smile:


#2

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


#3

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

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”


#5

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 :slight_smile: