I want to convert current data into 'yyyy-MM-dd'
format in .ts file. i template it can easily be done by using data pipe. how to do that in typescript.
In template:
{{date | date:'yyyy-MM-dd'}}
How to convert in this format 'yyyy-MM-dd'
in typescript.
now i am just getting current date by using this.
this.date = new Date();
but need to convert it into given format. Please guide how to do that... Thanks!
I would suggest you to have a look into Moment.js if you have trouble with Angular. At least it is a quick workaround without spending too much time.
You can also try this.
consider today's date '28 Dec 2018'(for example)
The date can be converted in typescript to this format
'yyyy-MM-dd'
by using Datepipeand just add Datepipe in 'providers' array of app.module.ts. Like this:
A simple solution would be to just write
date
.toLocaleDateString()
time.toLocaleTimeString()
both.toLocaleString()
Hope this helps.