Created
June 9, 2020 10:49
-
-
Save serefercelik/e1c4f25980bc98efed996d8b913d8119 to your computer and use it in GitHub Desktop.
moment.js from now
This file contains 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
let timing = new Date(date*1000); | |
//let timing = moment(date).format('MMMM Do YYYY, h:mm:ss a'); | |
//console.log(moment(timing).year()); | |
var start = moment(timing); | |
var end = moment(); | |
var duration = moment.duration(end.diff(start)); | |
var mins = duration.asMinutes(); // give mins | |
console.log(start.from(end)); // "a day ago" | |
return start.from(end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
moment.fn.fromNowOrNow = function (a) { if (Math.abs(moment().diff(this)) < 25000) { // 25 seconds before or after now return 'just now'; } return this.fromNow(a); }