Format date with Angular DatePipe

0

I have a date in the timestamp format and I wanted to format it for Portuguese text, for example: "Wednesday, October 18, 2017", but I put the pipe "| date: 'fullDate'" and it does not work. When I take the toLocaleString("pt-BR") and return a Date in the function it returns me "Wednesday, October 18, 2017". Thanks in advance!

Typescript

public dt: Date = new Date();
public getDate(): string {
  return this.dt.toLocaleString("pt-BR");
}

html

<div class="data"><b>{{getDate() | date:'fullDate'}}</b></div>
    
asked by anonymous 18.10.2017 / 18:02

1 answer

0

There is a project that already has a set of functions designed to work with Data, you can check it out:

link

But there is also an alternative:

$scope.getDate = function() {
    let dt = new Date();

    let month = ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'];
    let week  = ['Domingo', 'Segunda-feira', 'Terça-feira', 'Quarta-feira', 'Quinta-feira', 'Sexta-feira', 'Sábado'];

    let semana = week[dt.getDay()];
    let mes = month[dt.getMonth()];

    return semana + ', ' + dt.getDate() + ' de ' + mes + ', ' + dt.getFullYear();
}       
    
18.10.2017 / 20:20