Created
November 21, 2017 22:44
-
-
Save snobu/ede90156252e3386cb50622e0c1ed64a to your computer and use it in GitHub Desktop.
javascript time delta x days ago
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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