Full answer
Pipes transform a value for display only. The data in your class does not change. The four formatting pipes that every fresher meets:
date:{{ exam | date:'dd MMM yyyy' }}. Presets exist:short,medium,longDate,shortTime. The main gotchas are the letters.MMis month andmmis minutes.yyyyis the year andYYYYis the week-based year, which gives wrong results near new year.HHis 24 hour andhhis 12 hour (addafor AM or PM).currency:{{ fee | currency:'INR' }}shows the symbol for the locale, andcurrency:'USD':'code'shows the code. The default fraction digits depend on the currency.number(decimal):{{ avg | number:'1.1-2' }}means at least 1 integer digit, and 1 to 2 fraction digits. The value is rounded, not cut.percent:{{ ratio | percent }}. It multiplies by 100, so pass0.85to get 85 percent, not85.
Time zone gotcha. The date pipe converts a date to the browser's time zone unless you pass a third argument, for example date:'short':'UTC'. new Date('2026-12-04') is UTC midnight in JavaScript, so a user west of UTC who shows it with the date pipe sees 3 December. (If you pass the plain string '2026-12-04' to the pipe, Angular reads it as a local date, which hides the problem until the value goes through new Date.) Store full ISO timestamps and decide the display zone on purpose.
Locale gotcha. The default locale is en-US. Formats, month names and separators change with the locale. To use another locale, provide LOCALE_ID and register the data: registerLocaleData(localeHi) from @angular/common/locales/hi. Without the registered data Angular throws an error that the locale is missing.
Other points: a pipe call in a template is cheap because built-in pipes are pure (they run again only when the input reference changes). A null or undefined input returns null and prints nothing. For custom needs use Intl.DateTimeFormat in a computed value.
import { formatDate, formatNumber, formatPercent, formatCurrency } from '@angular/common';
const exam = new Date(Date.UTC(2026, 11, 4, 15, 5, 0)); // 4 Dec 2026, 15:05 UTC
export function samples(): string[] {
return [
formatDate(exam, 'dd MMM yyyy', 'en-US', 'UTC'),
formatDate(exam, 'MM/dd HH:mm', 'en-US', 'UTC'),
formatDate(exam, 'hh:mm a', 'en-US', 'UTC'),
formatDate(exam, 'shortTime', 'en-US', '+0530'),
formatNumber(3.14159, 'en-US', '1.1-2'),
formatPercent(0.856, 'en-US', '1.0-0'),
formatCurrency(1500, 'en-US', '$', 'USD', '1.2-2'),
];
}
// The same functions power the pipes: {{ exam | date:'dd MMM yyyy':'UTC' }}Angular 20.3 with the default en-US locale. The formatting calls were run in a Karma test in headless Chrome, and the outputs in the comments are the ones captured there.
Key points
- Pipes format for display only. The data does not change.
- Date letters: `MM` month, `mm` minutes, `yyyy` year, `HH` 24-hour. `YYYY` is a trap.
- `percent` multiplies by 100. `number:'1.1-2'` sets integer and fraction digits.
- Dates show in the browser time zone unless you pass one. Other locales need `registerLocaleData`.
Common mistakes
- Using `mm` for month or `YYYY` for year.
- Passing `85` to the percent pipe and getting 8500 percent.
- Building a `Date` from a date-only string and showing it in a time zone west of UTC.
Follow-ups
- How would you show a date in a fixed time zone?
- What does `1.2-2` mean in the number pipe?
- How do you add the Hindi locale?
Tips
- Show the `MM` versus `mm` mistake. Interviewers like it.
- Mention time zones without being asked.
- Say that built-in pipes are pure.
Evaluation rubric
- Explains each pipe with correct format syntax.
- Knows the date letter, zone and locale traps.
- Understands that pipes only change display.