Good afternoon, I'm starting to develop an application in Angular 6, and I need to display the date and time on the screen. I have already been able to present both, but they are in the American standard. How can I change to the Brazilian standard?
Good afternoon, I'm starting to develop an application in Angular 6, and I need to display the date and time on the screen. I have already been able to present both, but they are in the American standard. How can I change to the Brazilian standard?
I have. I've done the following:
import { registerLocaleData } from '@angular/common';
import localeBr from '@angular/common/locales/pt';
On the import of NgModule I also imported% with_%
Then
registerLocaleData(localeBr, 'pt')
And in the declaration of providers
{ provide: LOCALE_ID, useValue: 'pt' }
All this in the main module ( appmodule )
According to the official documentation of the Angular, you can use the predefined formats of DatePipe, or if you prefer, customize their formats, which I believe will be the right one for you. Read more about DatePipe at link
Use as follows:
//Classe do seu componente
class SuaClasse{
hoje: number = Date.now();
}
//no seu template
<div>
<p>Data e hora de hoje é {{ hoje | date:'dd/MM/yyyy HH:mm:ss' }}</p>
</div>
I hope I have helped!
For this you can use interpolation followed by the date
pipe.
Example in HMTL:
{{ variavelComAData | date: 'dd/MM/yyyy hh:mm:ss' }}
For more details see DatePipe documentation in the docs of the angular .