Update snippet descriptions

This commit is contained in:
Isabelle Viktoria Maciohsek
2020-10-22 20:24:30 +03:00
parent d35575373f
commit 5cb69e3c5c
58 changed files with 195 additions and 126 deletions

View File

@ -1,13 +1,13 @@
---
title: toISOStringWithTimezone
tags: date,math,intermediate
tags: date,intermediate
---
Returns a string in simplified extended ISO format (ISO 8601), including timezone offset.
Converts a date to extended ISO format (ISO 8601), including timezone offset.
- Use `Date.prototype.getTimezoneOffset()` to get the timezone offset and reverse it, storing its sign in `diff`.
- Define a helper function, `pad`, that normalizes any passed number to an integer using `Math.floor()` and `Math.abs()` and pads it to 2 digits, using `String.prototype.padStart()`.
- Use `pad` and the built-in methods in the `Date` prototype to build the ISO 8601 string with timezone offset.
- Define a helper function, `pad`, that normalizes any passed number to an integer using `Math.floor()` and `Math.abs()` and pads it to `2` digits, using `String.prototype.padStart()`.
- Use `pad()` and the built-in methods in the `Date` prototype to build the ISO 8601 string with timezone offset.
```js
const toISOStringWithTimezone = date => {