Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

482
Views
Formatee la fecha como dd/MM/yyyy usando canalizaciones

Estoy usando la tubería de date para formatear mi fecha, pero no puedo obtener el formato exacto que quiero sin una solución alternativa. ¿Estoy entendiendo mal las tuberías o simplemente no es posible?

 //our root app component import {Component} from 'angular2/core' @Component({ selector: 'my-app', providers: [], template: ` <div> <h2>Hello {{name}}</h2> <h3>{{date | date: 'ddMMyyyy'}}, should be {{date | date: 'dd'}}/{{date | date:'MM'}}/{{date | date: 'yyyy'}}</h3> </div> `, directives: [] }) export class App { constructor() { this.name = 'Angular2' this.date = new Date(); } }

ver plnkr

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Error de formato de fecha de tubería corregido en Angular 2.0.0-rc.2, esta solicitud de extracción.

Ahora podemos hacerlo de la manera convencional:

 {{valueDate | date: 'dd/MM/yyyy'}}

Ejemplos:

Versión actual:

Ejemplo Angular 13


Versiones antiguas:

Ejemplo Angular 8.xx

Ejemplo Angular 7.x

Ejemplo Angular 6.x

Ejemplo Angular 4.x

Ejemplo Angular 2.x


Más info en documentación DatePipe

over 4 years ago · Santiago Trujillo Report

0

Importe DatePipe desde angular/common y luego use el siguiente código:

 var datePipe = new DatePipe(); this.setDob = datePipe.transform(userdate, 'dd/MM/yyyy');

donde userdate será su cadena de fecha. A ver si esto ayuda.

Tome nota de las minúsculas para la fecha y el año:

 d - date M - month y - year

EDITAR

Debe pasar la cadena de locale como argumento a DatePipe, en el último angular. He probado en angular 4.x

Por ejemplo:

 var datePipe = new DatePipe('en-US');
over 4 years ago · Santiago Trujillo Report

0

Puede lograr esto usando una tubería personalizada simple.

 import { Pipe, PipeTransform } from '@angular/core'; import { DatePipe } from '@angular/common'; @Pipe({ name: 'dateFormatPipe', }) export class dateFormatPipe implements PipeTransform { transform(value: string) { var datePipe = new DatePipe("en-US"); value = datePipe.transform(value, 'dd/MM/yyyy'); return value; } }

Modelo:

 {{currentDate | dateFormatPipe }}

La ventaja de usar una tubería personalizada es que, si desea actualizar el formato de fecha en el futuro, puede ir y actualizar su tubería personalizada y se reflejará en todas partes.

Ejemplos de tuberías personalizadas

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!