i am making an ionic app v2 in which i have to show 'today' instead of current date and 'yesterday' and 'tomorrow' also for respective dates. i tried using moment but it gives days till last week like last monday and reference time issue is also there with moment. i need for only these 3 days without reference time . can you tell me how to customize moment in ionic framework ? if you have any other suggestions than using moment . please tell. thanks in advance. P.S: i want to implement this only in html code of ionic not in typescript code.
Asked
Active
Viewed 2,625 times
1
-
Can you give us any code base to work with? We do not know anything about your project. Note: It will be difficult without js/ts. – Stephan Strate Feb 09 '18 at 14:34
-
i am working on ionic framework with ts and html – pelu Feb 12 '18 at 08:21
2 Answers
0
Just like this: moment().add(-1, 'days')
. It will give you the previous day with the same exact current time that is on your local pc.
Ref here

Imdad Ali
- 727
- 1
- 8
- 18
-
i didn't get it where should i add this moment().add() function . is it in ts file? – pelu Feb 12 '18 at 08:20
0
Agreed that this will be difficult without JS/TS. In your .ts file couldn't you have 3 date member variables:
//Set up 3 new dates, defaulting them to today
yesterday: Date = new Date();
today: Date = new Date();
tomorrow: Date = new Date();
And then in your ctor or init method, set them up properly (below is likely not the most valid/efficient way, but is an example).
//Today is already set up from instantiation, but re-set tomorrow and yesterday
this.tomorrow.setDate(this.tomorrow.getDate() + 1);
this.yesterday.setDate(this.yesterday.getDate() - 1);
And then in your HTML, bind to them:
Yesterday was: {{yesterday?.toDateString()?.slice(0,10)}}
<br> Today is: {{today?.toDateString()?.slice(0,10)}}
<br> Tomorrow will be: {{tomorrow?.toDateString()?.slice(0,10)}}

BRass
- 3,698
- 2
- 28
- 46
-
Thanks for answering but what it is doing ..it shows dates. i don't need that. I already have dates coming. i want to show today, yesterday instead of that day date. – pelu Feb 12 '18 at 08:19