# Set the time of a date to midnight

Return the start of the UTC day of a date-time.

Canonical: https://1loc.dev/date-time/initialize-the-current-date-but-set-time-to-midnight/
Version: 1.0.0
Runtime: JavaScript · Node.js 22 / modern browsers
Verification: Local fixtures; no external services
Updated: 2026-10-28

## Implementation

```javascript
function midnightUtc(now) { const d = new Date(now); d.setUTCHours(0, 0, 0, 0); return d.toISOString(); }
```

## Input

```json
"2026-10-28T14:05:00Z"
```

## Expected output

```json
"2026-10-28T00:00:00.000Z"
```

## Edge case

Input:
```json
"2026-10-28T23:30:00-03:00"
```
Output:
```json
"2026-10-29T00:00:00.000Z"
```

## Limits

- The original used local midnight via setHours; this version is UTC so it is the same on every server. Use setHours for the reader’s local day.

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/initialize-the-current-date-but-set-time-to-midnight.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: Takes the time as an input and returns UTC midnight; the original used local midnight. Original MDX retained as inert source evidence.
