2018-09-30 23:01:58 +01:00
---
id: 587d778c367417b2b2512aa9
title: Standardize Times with the HTML5 datetime Attribute
challengeType: 0
videoUrl: 'https://scrimba.com/c/cmzMgtz'
2019-08-05 09:17:33 -07:00
forumTopicId: 301025
2021-01-13 03:31:00 +01:00
dashedName: standardize-times-with-the-html5-datetime-attribute
2018-09-30 23:01:58 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
2021-04-17 05:19:52 +01:00
Continuing with the date theme, HTML5 also introduced the `time` element along with a `datetime` attribute to standardize times. The `time` element is an inline element that can wrap a date or time on a page. A `datetime` attribute holds a valid format of that date. This is the value accessed by assistive devices. It helps avoid confusion by stating a standardized version of a time, even if it's informally or colloquially written in the text.
2020-11-27 19:02:05 +01:00
2018-09-30 23:01:58 +01:00
Here's an example:
2020-11-27 19:02:05 +01:00
2021-03-19 00:24:09 +01:00
```html
< p > Master Camper Cat officiated the cage match between Goro and Scorpion < time datetime = "2013-02-13" > last Wednesday< / time > , which ended in a draw.< / p >
```
2020-11-27 19:02:05 +01:00
# --instructions--
2021-04-28 01:07:43 -05:00
Camper Cat's Mortal Kombat survey results are in! Wrap a `time` tag around the text `Thursday, September 15<sup>th</sup>` and add a `datetime` attribute to it set to `2016-09-15` .
2020-11-27 19:02:05 +01:00
# --hints--
Your code should have a `p` element which includes the text `Thank you to everyone for responding to Master Camper Cat's survey.` and include a `time` element.
```js
2022-01-10 15:08:49 +02:00
assert(timeElement);
2020-11-27 19:02:05 +01:00
```
Your added `time` tags should wrap around the text `Thursday, September 15<sup>th</sup>` .
```js
assert(
2022-01-10 15:08:49 +02:00
timeElement & &
timeElement?.innerHTML?.trim() === 'Thursday, September 15< sup > th< / sup > '
2020-11-27 19:02:05 +01:00
);
```
Your added `time` tag should have a `datetime` attribute that is not empty.
```js
2022-01-10 15:08:49 +02:00
assert(datetimeAttr & & datetimeAttr?.length);
2020-11-27 19:02:05 +01:00
```
Your added `datetime` attribute should be set to a value of `2016-09-15` .
```js
assert(datetimeAttr === '2016-09-15');
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
# --seed--
## --after-user-code--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```html
< script >
2022-01-10 15:08:49 +02:00
const pElement = [...document.querySelectorAll("article > p")]
.filter(x => x?.textContent?.includes("Thank you to everyone for responding to Master Camper Cat's survey."));
const timeElement = pElement[0] ? pElement[0].querySelector("time") : null;
const datetimeAttr = timeElement?.getAttribute("datetime");
2020-11-27 19:02:05 +01:00
< / script >
```
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
## --seed-contents--
2018-09-30 23:01:58 +01:00
```html
< body >
< header >
< h1 > Tournaments< / h1 >
< / header >
< article >
< h2 > Mortal Kombat Tournament Survey Results< / h2 >
2018-10-08 01:01:53 +01:00
2020-02-27 07:20:46 -08:00
<!-- Only change code below this line -->
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
< p > Thank you to everyone for responding to Master Camper Cat's survey. The best day to host the vaunted Mortal Kombat tournament is Thursday, September 15< sup > th< / sup > . May the best ninja win!< / p >
2018-10-08 01:01:53 +01:00
2020-02-27 07:20:46 -08:00
<!-- Only change code above this line -->
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
< section >
< h3 > Comments:< / h3 >
< article >
< p > Posted by: Sub-Zero on < time datetime = "2016-08-13T20:01Z" > August 13< sup > th< / sup > < / time > < / p >
< p > Johnny Cage better be there, I'll finish him!< / p >
< / article >
< article >
< p > Posted by: Doge on < time datetime = "2016-08-15T08:12Z" > August 15< sup > th< / sup > < / time > < / p >
< p > Wow, much combat, so mortal.< / p >
< / article >
< article >
< p > Posted by: The Grim Reaper on < time datetime = "2016-08-16T00:00Z" > August 16< sup > th< / sup > < / time > < / p >
< p > Looks like I'll be busy that day.< / p >
< / article >
< / section >
< / article >
< footer > © 2018 Camper Cat< / footer >
< / body >
```
2020-11-27 19:02:05 +01:00
# --solutions--
2018-09-30 23:01:58 +01:00
2019-03-10 14:09:57 -04:00
```html
< body >
< header >
< h1 > Tournaments< / h1 >
< / header >
< article >
< h2 > Mortal Kombat Tournament Survey Results< / h2 >
2020-02-27 07:20:46 -08:00
2019-03-10 14:09:57 -04:00
< p > Thank you to everyone for responding to Master Camper Cat's survey. The best day to host the vaunted Mortal Kombat tournament is < time datetime = "2016-09-15" > Thursday, September 15< sup > th< / sup > < / time > . May the best ninja win!< / p >
2020-02-27 07:20:46 -08:00
2019-03-10 14:09:57 -04:00
< section >
< h3 > Comments:< / h3 >
< article >
< p > Posted by: Sub-Zero on < time datetime = "2016-08-13T20:01Z" > August 13< sup > th< / sup > < / time > < / p >
< p > Johnny Cage better be there, I'll finish him!< / p >
< / article >
< article >
< p > Posted by: Doge on < time datetime = "2016-08-15T08:12Z" > August 15< sup > th< / sup > < / time > < / p >
< p > Wow, much combat, so mortal.< / p >
< / article >
< article >
< p > Posted by: The Grim Reaper on < time datetime = "2016-08-16T00:00Z" > August 16< sup > th< / sup > < / time > < / p >
< p > Looks like I'll be busy that day.< / p >
< / article >
< / section >
< / article >
< footer > © 2018 Camper Cat< / footer >
< / body >
2018-09-30 23:01:58 +01:00
```