I simply want to create a date that is 3 days from now for use in a typescript angular component.
I have looked at Angular2 moment but this seems only to relate to pipes. Although I did see this article about using pipes in code, looks a bit hacky...
Maybe I'm missing something as this should be really simple?!
Thanks
Adding days to current Date const current = new Date(); Now, we can add the required number of days to a current date using the combination of setDate() and getDate() methods.
You have to pass the locale string as an argument to DatePipe. var ddMMyyyy = this. datePipe. transform(new Date(),"dd-MM-yyyy");
date: Date;
ngOnInit() {
this.date = new Date();
this.date.setDate( this.date.getDate() + 3 );
}
Then you can use the date pipe to display the date nicely in your HTML
{{ date | date }}
Which renders thusly:
Sep 25, 2017
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With