Skip to content

Instantly share code, notes, and snippets.

@snobu
Created November 21, 2017 22:44
Show Gist options
  • Select an option

  • Save snobu/ede90156252e3386cb50622e0c1ed64a to your computer and use it in GitHub Desktop.

Select an option

Save snobu/ede90156252e3386cb50622e0c1ed64a to your computer and use it in GitHub Desktop.
javascript time delta x days ago
async function parse() {
const feedparser = require('feedparser-promised');
const feedUrl = 'https://blogs.msdn.microsoft.com/appserviceteam/feed/';
let items = await feedparser.parse(feedUrl);
let title = items[0].title;
let date = Date.parse(items[0].pubDate);
let hoursDelta = Math.floor(date / 1000 / 60);
let daysDelta = hoursDelta % 24;
let result = `Here is the title of the most recent blog post: ${title}. ` +
`It was published ${daysDelta} days ago.`;
console.log(result);
}
parse();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment