FIND YOUR NEXT FEW LINES

The snippet library.

Small, practical examples. Search by task or narrow things down below.

10 snippets foundClear filters
JavaScriptUTC date operations

Add calendar days in UTC

JavaScript: Use UTC date setters to cross month boundaries without local daylight-saving effects.

JavaScript✓ Tested
JavaScriptUTC date operations

Construct a date from Unix seconds

JavaScript: Multiply seconds by 1000 before creating a Date.

JavaScript✓ Tested
JavaScriptUTC date operations

Convert epoch milliseconds to whole seconds

JavaScript: JavaScript Date stores milliseconds while many APIs use Unix seconds.

JavaScript✓ Tested
JavaScriptUTC date operations

Count days between UTC-midnight dates

JavaScript: A day is exactly 86400000 milliseconds for these explicitly UTC-midnight inputs.

JavaScript✓ Tested
JavaScriptUTC date operations

Detect an invalid Date object

JavaScript: An invalid Date has a NaN time value.

JavaScript✓ Tested
JavaScriptUTC date operations

Find the final day of a month

JavaScript: Day zero of the following UTC month selects the previous month’s final day.

JavaScript✓ Tested
JavaScriptUTC date operations

Format whole seconds as hours minutes and seconds

JavaScript: Use integer divisions and remainders for a nonnegative duration.

JavaScript✓ Tested
JavaScriptUTC date operations

Read an ISO-style weekday number

JavaScript: Convert Sunday from zero to seven when using Monday-through-Sunday numbering.

JavaScript✓ Tested
JavaScriptUTC date operations

Read date components in UTC

JavaScript: UTC accessors avoid differences caused by the machine’s local timezone.

JavaScript✓ Tested
JavaScriptUTC date operations

Sort timestamp strings by their parsed instants

JavaScript: Compare epoch values explicitly when date strings may contain different offsets.

JavaScript✓ Tested