# Add AM PM suffix to an hour

Turn an hour from 0 to 23 into a 12-hour label with am or pm.

Canonical: https://1loc.dev/date-time/add-am-pm-suffix-to-an-hour/
Version: 1.0.0
Runtime: JavaScript · Node.js 22 / modern browsers
Verification: Local fixtures; no external services
Updated: 2026-10-28

## Implementation

```javascript
function suffixAmPm(hour) { return `${hour % 12 === 0 ? 12 : hour % 12}${hour < 12 ? 'am' : 'pm'}`; }
```

## Input

```json
15
```

## Expected output

```json
"3pm"
```

## Edge case

Input:
```json
0
```
Output:
```json
"12am"
```

## Limits

- Input is an integer hour from 0 to 23.
- For text a reader sees, prefer Intl.DateTimeFormat in the reader’s locale.

The lab validates types and size before calling this function. Add equivalent validation at your own trust boundary.

## Source and license

Original: https://github.com/phuocng/1loc/blob/14b481cf60dff1620ab1bb99a43b1f68068cdd9b/contents/add-am-pm-suffix-to-an-hour.mdx
Author: Nguyen Huu Phuoc and original contributors
Contributors: See original repository history
Source commit: 14b481cf60dff1620ab1bb99a43b1f68068cdd9b
Copyright (c) 2020 phuoc-ng
License: MIT — https://1loc.dev/licenses/
Maintainer: Oveyon
Modifications: Original implementation kept; integer 0–23 validation and locale note. Original MDX retained as inert source evidence.
