Answer the question
In order to leave comments, you need to log in
Fetch, request with git hub api, how to properly format received dates?
https://codepen.io/fristyr/pen/arzQWL
I display information about my repositories by clicking, there is a date of the item.updated_at
last update, but not in the format in which I would like, can it be formatted somehow? For example, to display "March 4, 2019".
Answer the question
In order to leave comments, you need to log in
https://momentjs.com/
moment.locale('ru');
document.querySelector('#load').addEventListener('click', function load() {
fetch('https://api.github.com/users/fristyr/repos')
.then(r => r.json())
.then(data => {
const formatIn = 'YYYY-MM-DDTHH:mm:ss';
const formatOut = 'DD MMMM YYYY';
document.querySelector('.repo-wrapp').insertAdjacentHTML('afterbegin', data.map(item => `
<article class="repo">
<a href="${item.html_url}" class="repo__name">${item.name}</a>
<br>
<span class="repo__technology">${item.language}</span>
<span class="repo__update">${moment(item.updated_at, formatIn).format(formatOut)}</span>
</article>`
).join(' '));
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question