Format dates and times with Angular DatePipe
How Angular DatePipe produces 24-hour times, which format tokens to use for yyyy-MM-dd HH:mm:ss, and when locale, time zone and readability call for a different approach.
Angular's DatePipe turns a date value into a display string inside a template. Most people looking for a 24-hour format need one detail: uppercase H gives the 0–23 hour, and lowercase h gives the 1–12 hour. This review covers that detail, the format tokens behind date-and-time patterns like yyyy-MM-dd HH:mm:ss, and the cases where a 24-hour string helps or hurts readers. It draws on Angular's documented pipe behavior. No hands-on test results or measurements were supplied for this article, so none are claimed.
Short answer: getting a 24-hour time
Pass a custom format string that uses HH for the hour. Leave out the a token, which adds the AM/PM marker.
<!-- 24-hour time, e.g. 14:07 -->
{{ createdAt | date:'HH:mm' }}
<!-- 24-hour time with seconds -->
{{ createdAt | date:'HH:mm:ss' }}
<!-- Date and 24-hour time together -->
{{ createdAt | date:'yyyy-MM-dd HH:mm:ss' }}
<!-- 12-hour equivalent, for comparison, e.g. 2:07 PM -->
{{ createdAt | date:'h:mm a' }}
Midnight under HH renders as 00, not 12. Use H instead of HH if you don't want a leading zero on single-digit hours.
Is DatePipe the right tool for your use?
DatePipe is a good fit when you want a readable, consistent date or time in an Angular template and the formatting rules are simple. Its main benefit is that formatting stays declarative and next to the markup, with optional time zone and locale arguments. The key tradeoff is that the output is a display string, not data. It is fine for people to read, but it is a poor format to store, sort, send to an API or parse again later.
Prefer plain ISO 8601 text, usually from the Date object's toISOString method, when the value will be stored, exchanged between systems or compared. Also consider keeping a locale-driven predefined format instead of a hard-coded 24-hour pattern when your audience mostly expects 12-hour times. That includes many readers in the US, where the en-US predefined time formats use AM/PM.
What DatePipe actually changes
DatePipe does not modify the underlying value. Your component still holds the same Date object, number or string. The pipe reads that value at render time and outputs a new string built from the format pattern, the time zone and the locale. This is presentation, not data conversion. Changing the format string changes only what users see.
The pipe accepts a Date object, a number of milliseconds since the Unix epoch, or an ISO-style date string. The full template signature is shown below. Every argument after the pipe name is optional.
{{ value | date [ : format [ : timezone [ : locale ] ] ] }}
If you give no format, the default is mediumDate, which shows a date with no time. If you give no time zone, the pipe uses the time zone of the user's machine. That means two users can see different hours for the same stored instant. If you give no locale, the pipe uses the application's LOCALE_ID, which defaults to en-US.
Format tokens that matter for date and time
| Token | Meaning | Example output |
| yyyy | Four-digit calendar year | 2026 |
| MM | Month, two digits | 03 |
| dd | Day of month, two digits | 05 |
| HH | Hour 00–23 (24-hour) | 14 |
| H | Hour 0–23, no padding | 14 |
| hh | Hour 01–12 (12-hour) | 02 |
| h | Hour 1–12, no padding | 2 |
| mm | Minutes, two digits | 07 |
| ss | Seconds, two digits | 09 |
| SSS | Fractional seconds (milliseconds) | 042 |
| a | Day period marker | PM |
| ZZZZZ | Time zone offset in ISO 8601 style | +01:00 |
The example column assumes a value of 5 March 2026 at 14:07:09.042, displayed in a zone with a +01:00 offset. These outputs show how each token behaves according to the documented patterns. They are not captured test results.
Case mistakes in yyyy mm dd hh-mm-ss patterns
Searches often type the pattern in all lowercase, as yyyy mm dd hh-mm-ss. Used literally in DatePipe, that pattern produces the wrong result because the tokens are case-sensitive.
- Lowercase mm is minutes, so the month must be uppercase MM.
- Lowercase hh is the 12-hour clock without AM/PM, so afternoon times look like morning times. Use HH for 24-hour output.
- Uppercase YYYY is the week-numbering year, not the calendar year. Around New Year it can differ from yyyy, so use lowercase yyyy for ordinary dates.
The corrected forms of that pattern are:
<!-- Hyphen-separated time, as in the search query -->
{{ createdAt | date:'yyyy-MM-dd HH-mm-ss' }}
<!-- Conventional colon-separated time -->
{{ createdAt | date:'yyyy-MM-dd HH:mm:ss' }}
<!-- ISO 8601-style string with a literal T and offset -->
{{ createdAt | date:"yyyy-MM-dd'T'HH:mm:ssZZZZZ" }}
Separators such as hyphens, colons, spaces and slashes pass through as literal characters. Letters that should appear as plain text, like the T in an ISO-style timestamp, must be wrapped in single quotes so the pipe doesn't read them as a format token. Hyphenated times work, and they suit contexts like file names, where colons can be a problem. For text people will read, colons are the more familiar convention.
Predefined formats and locale
DatePipe offers named formats such as short, medium, long, full, shortDate, mediumDate, shortTime and mediumTime. These follow the active locale's conventions instead of a fixed pattern. Under en-US, the time-bearing presets use a 12-hour clock with AM/PM. Under locales whose conventions use a 24-hour clock, the same presets produce 24-hour times. If you need 24-hour output no matter the locale, use a custom pattern with HH. If you would rather respect each reader's regional habit, use the presets with the correct locale.
Locales other than en-US must be registered before the pipe can use them. If one is missing, Angular reports an error at runtime.
import { registerLocaleData } from '@angular/common';
import localeDe from '@angular/common/locales/de';
registerLocaleData(localeDe);
// In a template:
// {{ createdAt | date:'shortTime':undefined:'de' }}
Time zones
The second argument sets the time zone. It accepts an offset such as '+0100' or the abbreviation 'UTC'. A 24-hour format only removes ambiguity about the hour. It does not tell readers which zone the hour belongs to. When users may be in different regions, either show the zone (for example with a ZZZZ or ZZZZZ token) or fix the zone on purpose.
<!-- Always display in UTC, 24-hour -->
{{ createdAt | date:'yyyy-MM-dd HH:mm':'UTC' }} UTC
Setting defaults and formatting in TypeScript
In recent Angular versions, the DATE_PIPE_DEFAULT_OPTIONS injection token sets an application-wide default format and time zone. That saves you from repeating the same pattern in every template. The older DATE_PIPE_DEFAULT_TIMEZONE token is deprecated in its favor. Check which one your Angular version supports.
import { DATE_PIPE_DEFAULT_OPTIONS } from '@angular/common';
export const appConfig = {
providers: [
{
provide: DATE_PIPE_DEFAULT_OPTIONS,
useValue: { dateFormat: 'yyyy-MM-dd HH:mm', timezone: 'UTC' }
}
]
};
Outside templates, the formatDate function from @angular/common uses the same patterns. It needs an explicit locale argument. In standalone components, import DatePipe directly into the component's imports array. In NgModule-based code, it comes with CommonModule.
import { formatDate } from '@angular/common';
const label = formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss', 'en-US');
Will the result stay readable after copying or sharing?
DatePipe outputs ordinary characters: digits, letters and punctuation. It uses no special Unicode styling or visual tricks. Copying and pasting therefore carries over exactly the text that was displayed. What gets lost is context. A copied 14:07 says nothing about its time zone unless the format includes one. A copied 05/03 means different dates in different regions. If the text will be pasted into other systems or reports, prefer an unambiguous pattern such as yyyy-MM-dd HH:mm with an offset or a stated zone.
Reparsing is another limit. A string formatted for display may not parse back into the same instant, especially if it drops seconds, the zone or the year. Keep the original value, or an ISO 8601 copy, for anything that has to be processed again.
For accessibility, HTML provides the time element. Its datetime attribute holds a machine-readable value next to the human-readable text, which lets software read the exact timestamp whatever display format you chose. No evidence was supplied about how particular screen readers announce 24-hour or hyphen-separated times. If that matters for your audience, test with the assistive technology your users rely on rather than assuming one rendering works everywhere.
<time [attr.datetime]="createdAt.toISOString()">
{{ createdAt | date:'yyyy-MM-dd HH:mm' }}
</time>
Gaps in this review
This article relies on Angular's documented DatePipe behavior and general date-format conventions. It includes no version-specific benchmarks, browser compatibility measurements or assistive-technology test results, because none were supplied. Token behavior and the names of configuration options can change between Angular releases. Confirm details against the documentation for the version your project uses.